0

I am using android studio 4.2.2 when I try to change button background image with xml. my code is below

       <Button
        android:id="@+id/btn_ok"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:background="@drawable/btn_background"
        android:text="@string/ok"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toStartOf="@+id/btn_cancel"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintWidth_percent="0.3" />

this was working for the previous version of android studio. but now the buttons's background is always purple. any additional setting needed?

Keigo Igarashi
  • 113
  • 1
  • 1
  • 13

1 Answers1

1

Try this code

 <androidx.appcompat.widget.AppCompatButton
            android:id="@+id/btn_ok"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:background="@drawable/btn_background"
            android:text="@string/ok"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toStartOf="@+id/btn_cancel"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintWidth_percent="0.3"/>
Emad Seliem
  • 608
  • 1
  • 4
  • 5
  • yeah, it's working but why i can't do with – Keigo Igarashi Jul 17 '21 at 20:03
  • For a Button, the primary color defined in the app theme overrides any custom background you want to apply to a Button, but it is not the case for the AppCompatButton.So you can use "AppCompatButton"instead of Button. – Emad Seliem Jul 17 '21 at 20:07