can someone help me I'm using a button in android ,I'm unable to change the button color , this is my xml code :
<Button
android:id="@ id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
tools:layout_editor_absoluteX="133dp"
tools:layout_editor_absoluteY="584dp" />
CodePudding user response:
Use the attribute android:background
. For example:
<Button
android:id="@ id/button3"
<!-- ADD THE LINE BELOW -->
android:background="@color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
tools:layout_editor_absoluteX="133dp"
tools:layout_editor_absoluteY="584dp" />
If you can't see the color you want, please add it to the colors.xml
file stored in the values
folder.
This is an example of a colors.xml
file:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="black">#333333</color>
</resources>
You should already have this file, if not, add it.
CodePudding user response:
You can use Material Button and it's won't affect ripple and elevation of Button
<com.google.android.material.button.MaterialButton
android:layout_width="wrap_content"
app:backgroundTint=""ff0000"
android:text="Hello World"
android:layout_height="wrap_content" />
CodePudding user response:
Have a look in your themes.xml file .
Change to android:theme="@style/Theme.AppCompat.NoActionBar"