Issue
- Android Stidio 4.1.1
- SDK 29 (Android 10)
I trying to change button background color on xml, but it doesn't changed.
here's my code
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ff0000"/>
</LinearLayout>
I think it might be work fine, but it still purple color :(
Solution
if you are using Android Studio 4.1.1 you are probably using Theme.MaterialComponents check your themes.xml file
so you have to use this attribute
android:backgroundTint="#ff0000"
read this documentation for more information:
https://material.io/components/buttons
If you insist on using android:background you can change your button xml code like this to force it using appcompat :
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ff0000"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
or you can change the theme of all your project by changing the theme in themes.xml like this:
I hope this is useful.
Answered By - Ma Jeed
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.