Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't change button's background color in XML .Android studio

Android studio screenshot

I created TableLayout then buttons. The button's color was automatically set purple. So I can't change them right now. It's my first time here.

like image 493
Xaxage Avatar asked Nov 06 '20 13:11

Xaxage


5 Answers

don't use anything else use

<androidx.appcompat.widget.AppCompatButton
<!-- attributes-->
/>

instead of one

<Button
<!--attributes-->
/>

every thing will work nicely.

Happy coding.

like image 127
Shashank Pandey Avatar answered Oct 21 '22 13:10

Shashank Pandey


Android default color is Purple in the latest Android Studio version. To change the color of the Button, you need to add a single line of code in the XML i.e.

app:backgroundTint="@color/red"

That's all!

like image 44
Prateek Avatar answered Oct 21 '22 13:10

Prateek


It's purple because of default background Tint color. You can : change **app:backgroundTint ** instad of android:backgroundColor . In this case your backgroundTint will appear instead of background color

OR

add

app:backgroundTint="@null"

and after that your background color will appear.

OR

You can change the default theme in android manifest . For example :

android:theme="@style/Theme.AppCompat"

or

 android:theme="@style/Theme.AppCompat.NoActionBar"
like image 20
Mehdi Shadrooh Avatar answered Oct 21 '22 13:10

Mehdi Shadrooh


Add the attribute:

app:backgroundTint="@null"

like image 5
Rida Dhimni Avatar answered Oct 21 '22 15:10

Rida Dhimni


You might be using targetSdkVersion 30

Solution: change the theme.xml style from

<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">

to

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
like image 4
Hor Chanpheng Avatar answered Oct 21 '22 15:10

Hor Chanpheng