Reputation: 91195
I have achieved that to maintain the state of a button using selector XML component. See the code snippet for example.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Non focused states
-->
<item android:state_focused="false" android:state_selected="false"
android:state_pressed="false" android:drawable="@drawable/back_arrow_normal" />
<item android:state_focused="false" android:state_selected="true"
android:state_pressed="false" android:drawable="@drawable/back_arrow_hover" />
<!-- Focused states
-->
<item android:state_focused="true" android:state_selected="false"
android:state_pressed="false" android:drawable="@drawable/back_arrow_hover" />
<item android:state_focused="true" android:state_selected="true"
android:state_pressed="false" android:drawable="@drawable/back_arrow_hover" />
<!-- Pressed
-->
<item android:state_pressed="true" android:drawable="@drawable/back_arrow_hover" />
</selector>
Using this idea, we should have a minimum of two images. If I have ten buttons in a project then I should have twenty images in the resource drawable. To make support multiple density/screen size to the application then I need 60 (20X3) images.
I have two kind of thoughts, but I don't know how to implement them. They are:
Is there any other great Ideas are most needed. Because this increases the size of the application.
Please express your thoughts and ideas.
Upvotes: 3
Views: 249
Reputation: 9117
I guess, your button's backgrounds are not too complex. If they are not, then you can use 9-patch pngs, so, the number of drawables would reduce to just one set. 9-patch pngs would resize and scale as per the need.
But, if the bckgrounds are complex, multiple resources for each resolution is required.
Upvotes: 1