Android button background is taking the primary color
Since you are using a Theme.MaterialComponents.*
your Button
is replaced at runtime by a MaterialButton
.
Currently the backgroundTint
is still the default MaterialButton
style.It means that if you are using a custom android:background
, you have to make sure to null out backgroundTint
to avoid that the custom background doesn't get tinted with the attr/colorPrimary
defined in your theme.
You have to add app:backgroundTint="@null"
:
<Button app:backgroundTint="@null" android:background="@drawable/.."
In any case you don't need a custom background (btn_rounded_stroke
) in your case. You are just using a custom background only to define rounded corners. This feature is provided by default by the MaterialButton
, then just use the cornerRadius
attribute.
Use the standard MaterialButton
:
<com.google.android.material.button.MaterialButton android:layout_width="wrap_content" android:layout_height="48dp" style="@style/Widget.MaterialComponents.Button.OutlinedButton" app:strokeColor="#59CECE" app:cornerRadius="24dp"
When Material theme is used then Button view is mapped to MaterialButtton.There is one more way to setup the button background in this case.
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.DarkActionBar"... <item name="materialButtonStyle">@style/ColoredButton</item> </style> <style name="ColoredButton" parent="Widget.MaterialComponents.Button.TextButton"> <item name="backgroundTint">@color/customButtonColor</item> </style>
Try this .
Your Button:
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#FFFFFF" android:layout_margin="5dp" android:background="@drawable/round_btn" android:padding="20dp" android:text="My Text" />
Here is your round_btn drawable:
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="#008577" /> <corners android:radius="20dp" /></shape>