How to set background image for button in Android?
49,880
Solution 1
All drawables are compiled under a single resource name, i.e. drawable
. Android automatically chooses from which folder to take the drawable depending on the screen size, and hence you do not need to specifically point it out. Also, hard coding Android to use resources from a particular folder kind of defeats the purpose of having multiple folders for Android to choose from. To solve this issue, simply change:
android:background="@drawable-mdbi/button_focused_orange"/>
To
android:background="@drawable/button_focused_orange"/>
Solution 2
Should be @drawable/button_focused_orange
Not @drawable-mdpi/button_focused_orange
Comments
-
SampathKumar almost 2 years
I Imported one image inside the drawable-mdpi, then implemented the image from button, but an error occurs
no resource found here
. How do I fix this issue?I tried this:
main.xml
<Button android:id="@+id/imageButtonSelector" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable-mdpi/button_focused_orange"/>