I can’t change the button color (xml) in Android Studio

Asked

Viewed 385 times

-1

I can’t change the color of the button in Android Studio. Whenever I create a button by XML it takes the primary color that is set in Themes.xlm and when I set a color, the code does not error but the button does not change color. I did not find anywhere, how should I proceed?

Codigo XML setando a cor branca

Botão sem mudar de cor

2 answers

0


This is Luiz Felipe, baby?

So, there are some ways to change the button color, and if it’s getting the color of your theme, it’s probably the colorAccent.

Some of the ways are:

Create a new style and assign to the button (recommended for better standardization):

 <style name="Button.White" parent="ThemeOverlay.AppCompat">
        <item name="colorAccent">@android:color/white</item>
    </style>

That on the button would be:

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:theme="@style/Button.White"
    />

You can also try the backgroundTint for Apis >= 21:

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:backgroundTint="@android:color/white"
    />

Also look for how to set these values programmatically.

I hope I’ve helped.

  • This is Lucas! I tried Style and it didn’t work, but backgroundTint worked! Maybe it’s because of the API itself. Thank you so much for the strength. A hug!

-2

Greetings Luiz

<Button
android:id="@+id/Button"

android:text="Button"
android:textColor="#FFFFFF"
android:textSize="30sp"

android:layout_width="270dp"
android:layout_height="60dp"
android:background="@drawable/cor_do_button"
android:shadowColor="#A8A8A8"
android:shadowDx="0"
android:shadowDy="0"
android:shadowRadius="5"
/>

with Bhutan created go to the folder: app/Rest/drawable create a cor_do_button by clicking with mouse on the right side(right click) will appetize new mouse and vam apara "Drawable Resource file" create with the name cor_do_button(xml)

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<corners
android:radius="14dp"
/>
<solid
android:color="#11114F"
/>
<padding
android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp"
/>
<size
android:width="270dp"
android:height="60dp"
/>
<stroke
android:width="3dp"
android:color="#878787"
/>
</shape>

any duivda bate ai

  • Speak Jorge, thank you so much for the strength! But it hasn’t changed yet!! This second code, that arrow the button, changed the layout, it stopped being square and next to the XML code in AS appeared the blue color that was passed, but in the same View, it continues with the theme color(pink)... I’m thinking it’s some problem in my AS or in the projects I’m creating... Anyway thank you so much for the help!!

  • Look I suggest you fly to flutter or React Activate and much more practical

Browser other questions tagged

You are not signed in. Login or sign up in order to post.