Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

3.1K
Vistas
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.

over 4 years ago · Hanz Gallego
13 Respuestas
Responde la pregunta

0

I found a solution. inside the button tag, use

android:backgroundTint="#ccc"

replace #ccc in the above line with hex code for your preferred color. This should solve it.

over 4 years ago · Hanz Gallego Denunciar

0

Add the attribute:

app:backgroundTint="@null"

over 4 years ago · Hanz Gallego Denunciar

0

You can change style from design editor as shown in below image

enter image description here

over 4 years ago · Hanz Gallego Denunciar

0

To resolve the issue. In the xml replace background in "android:background="@android:color/black" with backgroundTint "android:backgroundTint="@android:color/black"

over 4 years ago · Hanz Gallego Denunciar

0

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">
over 4 years ago · Hanz Gallego Denunciar

0

enter image description here

You can use this button

<androidx.appcompat.widget.AppCompatButton>
over 4 years ago · Hanz Gallego Denunciar

0

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"
over 4 years ago · Hanz Gallego Denunciar

0

go to res-values-themes-themes you will find two themes. one is when dark mode is activated. Go and change the one in dark mode. what could be happening is you have a different style for dark mode. I really hope it was easy to understand since english is not my first language

over 4 years ago · Hanz Gallego Denunciar

0

don't use anything else use

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

instead of one

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

every thing will work nicely.

Happy coding.

over 4 years ago · Hanz Gallego Denunciar

0

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!

over 4 years ago · Hanz Gallego Denunciar

0

It's really easy. You should create a shape in XML. Set background to that shape then set background with that XML.

over 4 years ago · Hanz Gallego Denunciar

0

I had same problem, I tried almost everything and nothing worked! Seems like something has changed in Android Studio 4.1.1? idk.

[MY SOLUTION] So I used TextView instead of Button and set custom background and it worked for me :/ Hope this helps!

enter image description here

over 4 years ago · Hanz Gallego Denunciar

0

it worked well with the update on 'com.google.android.material:material:1.2.0-alpha06'

or

do it programmatically : myButton.background = ContextCompat.getDrawable(requireContext(), R.drawable.my_background)

both options, you'll need to set app:backgroundTint property as null

app:backgroundTint="@null"

check the next link: https://github.com/material-components/material-components-android/issues/889

over 4 years ago · Hanz Gallego Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda