Issue
I would like to create a custom button by using drawable, which is create like this:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/poll_checked" android:state_selected="true"/>
<item android:drawable="@drawable/poll"/>
</selector>
Then , I use the button in my tabhost like this
tabHost.addTab(tabSpec.setIndicator("",R.drawable.btn_survey),InfoFragment.class, null);
However, right now I need to choose from 600 icons, that means I need to create 600 xml and put them in drawable folder, which seems to be foolish. Are there any elegant way to tackle this? Thanks for helping, I already paste 1200 icons (600 select, 600 unselect) to the drawable-xxhdpi folder.
Solution
I achieved it as follows:
ImageView iv = (ImageView) view.findViewById(R.id.icon);
StateListDrawable mIcon = new StateListDrawable();
mIcon.addState(new int[] { android.R.attr.state_selected }, getResources().getDrawable(R.drawable.survey_checked));
mIcon.addState(StateSet.WILD_CARD, getResources().getDrawable(R.drawable.survey));
iv.setImageDrawable(mIcon);
Answered By - user3538235
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.