Android : Customizing tabs on state : How do I make a selector a drawable
Posted
by Chrispix
on Stack Overflow
See other posts from Stack Overflow
or by Chrispix
Published on 2009-04-21T17:30:48Z
Indexed on
2010/06/11
17:32 UTC
Read the original article
Hit count: 447
I know how to put the icon on each tab, that is no problem. I also ran across this : Stack Overflow thread on pretty much same thing
I followed one of the links from that question, and found this
Pretty much, it said use a selector defined in the xml, sure, did that. But there is no id associated w/ it so I am not sure how to get the selector function as a drawable so I can use it as the icon for the tabs. Maybe I am going about this the wrong way.. But this is what I have, and obviously missing something.
<selector
android:id="@+id/myselector"
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/darklogo" />
<item
android:state_focused="false"
android:state_selected="true"
android:state_pressed="false"
android:drawable="@drawable/lightlogo" />
<!-- Focused states -->
<item
android:state_focused="true"
android:state_selected="false"
android:state_pressed="false"
android:drawable="@drawable/lightlogo" />
<item
android:state_focused="true"
android:state_selected="true"
android:state_pressed="false"
android:drawable="@drawable/lightlogo" />
<!-- Pressed -->
<item
android:state_pressed="true"
android:drawable="@drawable/lightlogo" />
</selector>
In my code, an example tab is generated using :
host.addTab(host.newTabSpec("three")
.setIndicator("map",drawables)
.setContent(new Intent(this, Map.class)));
Right now drawables is just a reference to an drawable image resource. How do I make the selector a drawable? * This is my question *
© Stack Overflow or respective owner