Change icon when focus and unfocus Android Tab widget
Hey I'd 开发者_如何转开发like to change the icon from the TabWidget on Android by focusing and unfocusing the tab. I mean, when I select the Tab, the icon shows for example green, and when I select the oter tab, the icon changes to red.
I'm calling a unique icon this way:
tabHost.addTab(tabHost.newTabSpec("one").setIndicator("Rated Calls", res.getDrawable(R.drawable.ratedcallicon))
How to make it change the image of the icon when I select other tab?
Thanks!
Every drawable has the ability to take up multiple images based on its current state (see how it has a setState
member. You could use StateListDrawable
, or even specify the states in XML.
There is a state for "focused", and FWIK that works on tabs.
精彩评论