Issue
I have button like this in my login activity layout.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:weightSum="2">
<com.google.android.material.button.MaterialButton
android:id="@+id/button_login_activity"
android:layout_width="0dp"
android:layout_height="60dp"
android:layout_weight="1"
android:text="Login"
app:cornerRadius="20dp"
android:background="@color/colorPrimaryDark"
android:textColor="@color/toolbar_text"
android:textStyle="bold" />
<com.google.android.material.button.MaterialButton
android:id="@+id/button_skip_login_activity"
android:layout_width="0dp"
android:layout_height="60dp"
android:layout_marginStart="10dp"
android:layout_weight="1"
app:cornerRadius="20dp"
android:background="@color/colorPrimaryDark"
android:textColor="@color/toolbar_text"
android:text="Skip"
android:textStyle="bold"
android:layout_marginLeft="10dp" />
</LinearLayout>
My Style is like this
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!--Common Color-->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:alertDialogTheme">@style/AlertDialogTheme</item>
<item name="windowActionBar">true</item>
<item name="windowNoTitle">true</item>
<item name="colorSwitchThumbNormal">@color/switch_normal</item>
<item name="colorControlNormal">@color/switch_normal</item>
<item name="android:textColorSecondary">@color/switch_normal</item>
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
<item name="android:windowDisablePreview">true</item>
</style>
I have dependency like below
implementation 'com.google.android.material:material:1.2.1'
I have tried many things but unable to make it working for round corner, same thing is working for my another project. Let me know if anyone can help me for come out from the issue. Thanks!
Solution
You have to remove the background:
android:background="@color/colorPrimaryDark"
Using it the MaterialButton
doesn't use its own MaterialShapeDrawable
for the background. This means that features like shape appearance, stroke and rounded corners are ignored.
In your case use the app:backgroundTint
attribute:
<com.google.android.material.button.MaterialButton
app:backgroundTint="@color/colorPrimaryDark"
Answered By - Gabriele Mariotti
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.