Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: Change Tab Text Color Programmatically
    primarykey
    data
    text
    <p>I've a TabHost like this:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;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"&gt; &lt;LinearLayout android:id="@+id/LinearLayout01" android:orientation="vertical" android:layout_height="fill_parent" android:layout_width="fill_parent"&gt; &lt;TabWidget android:id="@android:id/tabs" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_marginBottom="5dip"&gt; &lt;/TabWidget&gt; &lt;FrameLayout android:id="@android:id/tabcontent" android:layout_height="fill_parent" android:layout_width="fill_parent"&gt; &lt;/FrameLayout&gt; &lt;/LinearLayout&gt; </code></pre> <p></p> <p>And I am adding tabs to this TabHost programmatically like this:</p> <pre><code>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&lt;tabHost.getTabWidget().getChildCount();i++) { tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#121312")); } tabHost.getTabWidget().setCurrentTab(0); tabHost.getTabWidget().getChildAt(0).setBackgroundColor(Color.parseColor("#f1a026")); </code></pre> <p>And here is onTabChanged Event:</p> <pre><code>public void onTabChanged(String tabId) { // TODO Auto-generated method stub for(int i=0;i&lt;tabHost.getTabWidget().getChildCount();i++) { tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#121312")); } tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundColor(Color.parseColor("#f1a026")); } </code></pre> <p>In onTabChanged event, I also want to change the text color of all tabs. Please help me how can I change text color of tabs in the event?</p> <p>Thanks,</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload