0

I am new to kotlin programming and i can't resolve the problem that i am facing in android studio. I followed a course on youtube, and at one point the video teaches you how to build an actual app. I want to change the backgroud color of a button that i made but whatever i do, the button keeps having the color purple.

I tryed this 2 methods:

android:background="@android:color/white"
android:background="#FFFFFF"

Can you help me guys, i would be really thankful

the entire code is: ( please do not mind the names i chose for the colors, im romanian)

<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:id="@+id/padding"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/backgroundColor"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="16dp"
tools:context=".MainActivity"
>

<Button
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="15dp"
    android:background="@android:color/white"
    android:backgroundTint="@color/white"
    android:text="Selecteaza data"
    android:textColor="@color/culoarePrimara"
    android:textSize="20sp"
    android:textStyle="bold"
    />
</LinearLayout>

This is the color: enter image description here

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
  • post more code, `Activity` and layout XML especially. where have you put this not-working `android:background` line? – snachmsm Feb 03 '21 at 13:28
  • Did you check colors.xml if "white" has the correct code? – MitjaHD Feb 03 '21 at 14:07
  • Guys, i do not know what to say, thank you for all the responses, i got pretty mad, deleted the project and re-coded it, using your sugestions and it worked thanks – Cosmin Boeriu Feb 09 '21 at 11:29
  • 1
    Does this answer your question? [Android button background color](https://stackoverflow.com/questions/18070008/android-button-background-color) (specifically [this answer](https://stackoverflow.com/a/47327294/208273)) or [this question](https://stackoverflow.com/q/29801031/208273) for doing it in Kotlin. – Ryan M Feb 17 '21 at 04:17

3 Answers3

0

For button background color either use custom style or android:backgroundTint="@color/white" (or your preferred color)

digiwizkid
  • 791
  • 2
  • 14
  • 28
0

instead of android:background="@color/backgroundColor"

use: android:backgroundTint="@color/backgroundColor"

Nicola Gallazzi
  • 7,897
  • 6
  • 45
  • 64
YZN
  • 133
  • 1
  • 8
0

You can use:

<Button
    app:backgroundTint="@color/..."/>

May be you are using a Theme.MaterialComponents.* theme and the default background color of the Button (which is replaced by a MaterialButton) is the colorPrimary defined in your app theme.

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841