Reputation: 166
I'm trying to change the color of a button, but it doesn't work.
btn_sign_in.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="23dp" />
<size android:height="16dp" />
<solid android:color="#045762" />
</shape>
and I gave android:background="@drawable/btn_sign_in"
in the button xml.
Upvotes: 0
Views: 1033
Reputation: 365018
You don't need to use a custom background.
Just use:
<com.google.android.material.button.MaterialButton
app:cornerRadius="23dp"
app:backgroundTint="#045762"
android:text="BUTTON"
.../>
Upvotes: 3
Reputation:
You can change the background color like this.
<Button
android:background="@android:color/green"
android:textColor="@android:color/white" />
Upvotes: 0
Reputation: 131
XML:
<Button
android:background="@android:color/white"
android:textColor="@android:color/black"/>
Programmatically:
btn.setBackgroundColor(Color.WHITE);
btn.setTextColor(Color.BLACK);
Upvotes: 0
Reputation: 923
hi have you tried app:backgroundTint="#045762"
, this will work in may cases but if u have to use a drawable then do this
app:backgroundTint="@null"
android:background="@drawable/btn_sign_in"
When using MatertialComponents Background tint will be given priority over the background and in your case, you can try to pass color directly as backgroundTint
also check out MaterialButton from MaterialComponents
Upvotes: 0