I have followed tutorial here about Tab view. Each Tab have now an image but when I select some tab then it doesnt got replaced with dark image. Is there some trick that I am missing. Forexample code for one tab is
spec = tabHost.newTabSpec("create开发者_如何学JAVA").setIndicator("Create",
res.getDrawable(R.drawable.testimg))
.setContent(intent);
tabHost.addTab(spec);
Then I created create.xml
with following contents
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- When selected, use grey -->
<item android:drawable="@drawable/testimg2"
android:state_selected="true" />
<!-- When not selected, use white-->
<item android:drawable="@drawable/testimg" />
</selector>
So when I select Create tab then its image should have been replaced by testimg2.png but it is not happening. Rest of the code is similar as tutorial. What am I missing here that selected image is not being toggled.
Thanks
You did it like this, right?:
spec = tabHost.newTabSpec("create").setIndicator("Create",
res.getDrawable(R.drawable.testimg))
.setContent(intent);
tabHost.addTab(spec);
you'll have to set the drawable to be 'create.xml'
put 'create.xml' inside 'drawable' folder (no hdpi, ldpi, mdpi. if any 'drawable' folder doesn't exist, create one) (Although it may not be necessary to put it inside a 'drawable' folder only, and perhaps you can put it under other drawable folders too, I haven't researched on that, but its a good practice)
then set it like this-
res.getDrawable(R.drawable.create)
It should work then.
精彩评论