मैंने इस तरह की एक TabHost:एंड्रॉयड: बदलें टैब पाठ का रंग प्रोग्राम
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@android:id/tabhost"
android:background="@drawable/tabs_bg">
<LinearLayout
android:id="@+id/LinearLayout01"
android:orientation="vertical"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<TabWidget
android:id="@android:id/tabs"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_marginBottom="5dip">
</TabWidget>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
</FrameLayout>
</LinearLayout>
और मैं इस तरह इस TabHost के लिए टैब द्वारा जोड़ा जा रहा प्रोग्राम के रूप में:
tabHost = (TabHost)findViewById(android.R.id.tabhost);
tabHost.setOnTabChangedListener(this);
/* tid1 is firstTabSpec Id. Its used to access outside. */
TabSpec firstTabSpec = tabHost.newTabSpec("tid1");
TabSpec secondTabSpec = tabHost.newTabSpec("tid2");
TabSpec ThirdTabSpec = tabHost.newTabSpec("tid3");
/* TabSpec setIndicator() is used to set name for the tab. */
/* TabSpec setContent() is used to set content for a particular tab. */
firstTabSpec.setIndicator("Tab1", getResources().getDrawable(R.drawable.tab1));
secondTabSpec.setIndicator("Tab2", getResources().getDrawable(R.drawable.tab2));
ThirdTabSpec.setIndicator("Tab3", getResources().getDrawable(R.drawable.tab3));
firstTabSpec.setContent(new Intent(this,FirstTab.class));
secondTabSpec.setContent(new Intent(this,SecondTab.class));
ThirdTabSpec.setContent(new Intent(this,ThirdTab.class));
/* Add tabSpec to the TabHost to display. */
tabHost.addTab(firstTabSpec);
tabHost.addTab(secondTabSpec);
tabHost.addTab(ThirdTabSpec);
for(int i=0;i<tabHost.getTabWidget().getChildCount();i++)
{
tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#121312"));
}
tabHost.getTabWidget().setCurrentTab(0);
tabHost.getTabWidget().getChildAt(0).setBackgroundColor(Color.parseColor("#f1a026"));
और यहाँ ऑनबैब चेंज इवेंट:
public void onTabChanged(String tabId) {
// TODO Auto-generated method stub
for(int i=0;i<tabHost.getTabWidget().getChildCount();i++)
{
tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#121312"));
}
tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundColor(Color.parseColor("#f1a026"));
}
ऑनबैब चेंजेड ईवेंट में, मैं सभी टैब के टेक्स्ट रंग को भी बदलना चाहता हूं। कृपया मेरी मदद करें कि मैं ईवेंट में टैब का टेक्स्ट रंग कैसे बदल सकता हूं?
धन्यवाद,
हाय फरहान! इस मामले में android.R.id.title क्या है? –
@ फ़ारहान, मेरे कोड में आईडी "शीर्षक" के साथ कुछ भी नहीं है। कृपया मेरे कोड की समीक्षा करें और मुझे बताएं कि मुझे एंड्रॉइड.R.id.title को क्या बदलना चाहिए? –
जैसा कि मैंने कहा था कि टैब का उपयोग करते समय, यह स्वचालित रूप से ढांचे द्वारा जोड़ा जाता है ....इसकी तरह जब आप setIndicator (पहला तर्क) में टेक्स्ट सेट करते हैं, तो यह टेक्स्ट id android.R.id.title के साथ टेक्स्टव्यू पर सेट होता है .... बस इसे प्राप्त करें और रंग बदलें ... – Farhan