खैर यह दूर था और अधिक जटिल की तुलना में मैंने सोचा कि यह होना चाहिए लेकिन, फिर भी, यह आप उपस्थिति है कि आप चाहते हैं की एक बुनियादी कार्यान्वयन मिलना चाहिए ...
TabHost host = getTabHost();
TabSpec spec = null;
TextView tab1 = null,
tab2 = null;
Intent intent = null;
Resources resources = getResources();
XmlResourceParser parser = null;
ColorStateList text = null;
StateListDrawable[] drawables = new StateListDrawable[2];
int[] selected = {STATE_SELECTED},
unselected = {STATE_UNSELECTED};
Color selectedColor = Color.argb(255, 255, 255, 255),
defaultColor = Color.argb(255, 119, 119, 119);
// Load the colour lists.
parser = resources.getXml(R.color.tab_text);
text = ColorStateList.createFromXml(getResources(), parser);
// Add an initial tab.
...Create Tab Contents Here...
spec = host.newTabSpec("tab1");
tab1 = new TextView(this);
tab1.setText(R.string.all_tab_title);
tab1.setGravity(android.view.Gravity.CENTER);
tab1.setTextSize(18.0f);
tab1.setTextColor(text);
spec.setIndicator(tab1);
spec.setContent(intent);
host.addTab(spec);
// Add a second tab.
...Create Tab Contents Here...
spec = host.newTabSpec("tab2");
tab2 = new TextView(this);
tab2.setText(R.string.category_tab_title);
tab2.setGravity(android.view.Gravity.CENTER);
tab2.setTextSize(18.0f);
tab2.setTextColor(text);
spec.setIndicator(tab2);
spec.setContent(intent);
host.addTab(spec);
// Set the background drawable for the tabs and select the first tab.
drawables[0] = new StateListDrawable();
drawables[0].addState(selected, new ColorDrawable(selectedColor));
drawables[0].addState(unselected, new ColorDrawable(defaultColor));
drawables[1] = new StateListDrawable();
drawables[1].addState(selected, new ColorDrawable(selectedColor));
drawables[1].addState(unselected, new ColorDrawable(defaultColor));
tab1.setBackgroundDrawable(drawables[0]);
tab2.setBackgroundDrawable(drawables[1]);
host.setCurrentTab(0);
यह टैब सीमाओं या रिक्ति betwee के लिए खाते में नहीं होंगे हालांकि एन तत्व। आपको ./res/color निर्देशिका में निम्न की तरह रंग स्थिति सूची परिभाषा भी चाहिए ...
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:color="#ff000000" />
<item android:state_selected="false" android:color="#ffaaaaaa" />
<item android:color="#ffffffff"/>
</selector>
आशा है कि इससे मदद मिलती है।
वाह, यह निश्चित रूप से मुझे लगता है कि यह बहुत अधिक है, मुझे लगता है कि जब तक कोई अधिक निश्चित तरीके से पोस्ट नहीं करता है तब तक मैं यह उत्तर स्वीकार करूंगा। – hwrdprkns
STATE_SELECTED और STATE_UNSELECTED आईडी का क्या माना जाता है? – pakore
@pakore - इन परिभाषाओं की उपेक्षा करने के लिए क्षमा चाहते हैं। STATE_SELECTED को एंड्रॉइड.R.attr.state_selected के बराबर के रूप में परिभाषित किया गया है। STATE_UNSELECTED STATE_SELECTED * -1 के बराबर है। – Woody