0

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

.

1 Answers1

0

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

<Button
    ...
    app:backgroundTint="@color/next_button_color"/>
Sdghasemi
  • 5,370
  • 1
  • 34
  • 42
  • okay thankyou soo much dear. May GOD bless you. Can you please tell me difference b/w material button and simple button? – MUHAMMAD HASEEB Jul 20 '21 at 06:51
  • You're welcome, If the answer helped mark it as the accepted answer to help others as well. Material button are normal buttons styled per [Google Material design guidelines](https://material.io/design/guidelines-overview), including shadow, inset, corner radius, touch gestures, etc. which is drawn on all API versions the same by the help of [Android support library](https://material.io/develop/android/docs/getting-started). – Sdghasemi Jul 20 '21 at 07:12
  • @MUHAMMADHASEEB About the difference you can check https://stackoverflow.com/questions/57925853/is-any-difference-between-a-materialbutton-and-a-simple-button/57926083#57926083 – Gabriele Mariotti Jul 20 '21 at 08:59