What is the trickiest way you have used Android Color State List?
I have used the android color state lists a lot for various things and they seem to not be well known in Android development even though they are really useful. So I want to know what it the trickiest or coolest thing you have down with them?
- Background behind transparent PNGs?
- Changing text colors on Custom Tabs?
- Cha开发者_开发技巧nging complete layouts?
Let me and others know the potential of this great tool.
Android ColorStateList
Using ColorStateList for tabs:
ColorStateList tabCSL = ColorStateList.createFromXml(getResources(),
resources.getXml(R.color.tab_text_csl));
TabHost host = getTabHost();
TabSpec spec = host.newTabSpec("tab1");
TextView txtTab = new TextView(this);
txtTab.setText(R.string.tab_string);
txtTab.setGravity(Gravity.CENTER);
txtTab.setTextColor(tabCSL);
spec.setIndicator(txtTab);
spec.setContent(someIntentYouMadeEarlier);
host.addTab(spec);
XML of /res/color/tab_text_csl.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:color="@color/white" />
<item android:color="@color/dark_grey"/>
</selector>
精彩评论