Haseeb Wajid
Haseeb Wajid

Reputation: 39

why i can'nt be able to change the color of buttons

I have added new colors in color.xml and set those color in main.xml file to buttons but the color of my buttons is still blue/default i don'nt know why this happen. if anyone know what is the problem then please help me to solve this issue.

Code of color.xml file is:

<resources>
<color name="purple_200">#FFBB86FC</color>
<color name="purple_500">#FF6200EE</color>
<color name="purple_700">#FF3700B3</color>
<color name="teal_200">#FF03DAC5</color>
<color name="teal_700">#FF018786</color>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
<color name="share_button_color">#271B1B</color>
<color name="next_button_color">#21EA13</color>

main.xml file code is:

<Button
    android:id="@+id/sharememe"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:padding="20dp"
    android:text="share"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toLeftOf="@id/guideline2"
    app:layout_constraintTop_toBottomOf="@id/guideline3"
    android:onClick="Sharememe"
    android:background="@color/share_button_color" />

<Button
    android:id="@+id/nextmeme"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:padding="20dp"
    android:text="next"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toRightOf="@id/guideline2"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@id/guideline3"
    tools:layout_editor_absoluteX="269dp"
    tools:layout_editor_absoluteY="540dp"
    android:onClick="Nextmeme"
    android:background="@color/next_button_color"/>


 

    

AVD image before add colors is :

before

AVD image after add colors is :

after

.

Upvotes: 0

Views: 55

Answers (1)

Sdghasemi
Sdghasemi

Reputation: 5598

Material buttons use backgrountTint attribute to colorize their background not background attribute, So replace background attribute with:

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

Upvotes: 0

Related Questions