In order to create custom buttons in Android I create a XML file where I specify the normal and pressed images to be used on the button, like this:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/buttonPressed" />
<item android:drawable="@drawable/buttonNormal" />
</selector>
Question: I will have different images for all dpi (so images on the ldpi, mdpi, hdpi and xhdpi folders). But do I also need to copy that XML file into each of those folders?
I know with a single button it doesn’t make a difference, but with dozens of them it might save me a lot of work if I don’t need to put the XML files on all folders.
Make a seperate drawable folder called
drawablethat contains .xml(s) that work for all sizes, such as gradients, shapes, or multi state buttons. If you have multiple dpi’s of an image, android will select the appropriate one.For example, your file tree might look like this: