Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Majdi Jaigirdar
4,421 PointsBackground colour doesn't change, stays as default purple
The colour of the button doesn't change to white when I change it. And the android white doesn't seem to be alliable from the resource page, so I had to add it from to the XML code, this is what my button view code looks like:
<Button
android:id="@+id/showFactButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_marginBottom="1dp"
android:background="@android:color/white"
android:text="Show another fun fact" />
However the button is still the default purple, I think the issue might have to do with Aneroids new 'material you' colour theme? When I tried to use @color/white or #FFFFFFFF it was still purple. When I run the app on my Pixel 6 , the button is a light purple colour instead.
Any ideas on why this is happening and how to change or fix this?
Edit & answer:
I got help from ChatGPT
So basically newer version of android use android:backgroundTint to define the button backgrounds, so I need to use:
android:backgroundTint="@color/white" Instead of android:background="@android:color/white"
Majdi Jaigirdar
4,421 PointsMajdi Jaigirdar
4,421 PointsAnswer: I got help from ChatGPT, it said:
"In newer versions of Android, the button color is typically defined using the
backgroundTintattribute instead of thebackgroundattribute. Thebackgroundattribute is used for setting the background drawable for the button, whilebackgroundTintis used to specify the color tint applied to the background.To change the button color to white, you can modify your code as follows:
Make sure you have a
whitecolor defined in yourcolors.xmlfile under theres/values/directory. If you don't have it, you can add it manually:<color name="white">#FFFFFF</color>With these changes, the button should now have a white background color."
So basically new version of android use
android:backgroundTintto define the button backgrounds, so I need to use:android:backgroundTint="@color/white"