For example to create a button whose button_normal
state shows some different style and button_pressed
state shows some different style, we create three files:
button_normal.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#0084FF" />
</shape>
button_pressed.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#FF19F4" />
</shape>
And finally, button.xml
<?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/button_pressed" />
<item android:drawable="@drawable/button_normal" />
</selector>
As you can see, inside the button.xml
file we are pointing the button_normal.xml
and button_pressed.xml
. Ok fine that is normal.
Actual consideration:
Now the question is that is this possible to add the source of button_normal.xml
and button_pressed.xml
inside the button.xml
and point the these two shapes (button_normal
and button_pressed
) within the same file button.xml
as:
<?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/button_pressed" />
<item android:drawable="@drawable/button_normal" />
</selector>
<shape android:shape="rectangle">
<solid android:color="#0084FF" />
<corners android:radius="3dp" />
</shape>
<shape android:shape="rectangle">
<solid android:color="#FF19F4" />
</shape>
The summary of the question is that is this possible to create multiple shapes within one xml
file and point them in the same file to something else (if needed) - for example see the above source? So in that case we will not create extra files for each shape.
Thanks in advance!!!