I have a drawable file that I put as the background for the button:

 <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/tab_selected" android:state_pressed="true"/> <item android:drawable="@color/white" android:state_focused="true"/> <item android:drawable="@color/white"/> </selector> 

I use gradient :

 <?xml version="1.0" encoding="utf-8"?> <gradient xmlns:android="http://schemas.android.com/apk/res/android" > <shape xmlns:android="http://schemas.android.com/apk/res/android" > <gradient android:angle="270" android:endColor="@color/gray" android:startColor="@color/dark_gray" /> </shape> </gradient> 

Without using gradient everything worked, but now, when I try to set the background for the button via setBackgroundResource(R.drawable.button2) , the application crashes with the message "Application Stopped." What did I do wrong in the gradient or somewhere else?

PS The colors are assigned correctly and the drawable file drawable without using the gradient too.

    1 answer 1

    What are you doing too much namudri, remove the external gradient

     <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" > <gradient android:angle="270" android:endColor="@color/gray" android:startColor="@color/dark_gray"> </gradient> </shape> 
    • Thank! After 7 minutes, I will accept the answer, writes that "early" :). It all worked! Well ... Earned did not work, nothing happens, but the error no longer gives: D. - user189127
    • @ bukashka101 Well, well, if you stick an android:shape="rectangle" in shape android:shape="rectangle" for example - ermak0ff
    • I don’t understand how it all works, I just copied code from stackoverflow. But, oddly enough, I accidentally painted over the entire button and it turned out more beautiful than I xD. However, to understand this thing will not hurt me. I'm going to try now. - user189127
    • It did not help, the effect is the same. - user189127
    • @ bukashka101 but what if you add <solid android: color = "# FFBBAADD" /> does something change? - ermak0ff