Skip to content Skip to sidebar Skip to footer

Android Tabwidget In Light Theme

I have an application that targets the 1.5 framework and uses the default light theme. When using a tab widget with this theme, the tab images are barely visible, and the tab capti

Solution 1:

it's not pretty, but you can try this in your tab activity.

// light theme supportfinalTabHosttabHost= getTabHost();
tabHost.setBackgroundColor(Color.WHITE);
tabHost.getTabWidget().setBackgroundColor(Color.BLACK);

// hack to set font sizeLinearLayoutll= (LinearLayout) tabHost.getChildAt(0);
TabWidgettw= (TabWidget) ll.getChildAt(0);

// first tabRelativeLayoutrllf= (RelativeLayout) tw.getChildAt(0);
lf = (TextView) rllf.getChildAt(1);
lf.setTextSize(21);
lf.setPadding(0, 0, 0, 6);

// second tabRelativeLayoutrlrf= (RelativeLayout) tw.getChildAt(1);
rf = (TextView) rlrf.getChildAt(1);
rf.setTextSize(21);
rf.setPadding(0, 0, 0, 6);

/res/values/colors.xml should have

<resources><drawablename="black">#ff000000</drawable><drawablename="white">#ffffffff</drawable></resources>

AndroidManiest.xml should have

<applicationandroid:theme="@android:style/Theme.Light">

if you want to do something crazier, try http://ezmobile.wordpress.com/2009/02/02/customized-android-tabs/

Solution 2:

This is a bug; can you report it in the the issue tracker?

AFAIK, your workaround of customizing the text and image styles sounds right.

It's also noteworthy that the tab widget in 2.0 doesn't seem to have a light style.

Solution 3:

By using the hierarchyviewer tool I found the android id for the textview in the tab. A better way to change the text properties (including color) is by doing the following...

TabWidgettw= (TabWidget)tabHost.findViewById(android.R.id.tabs);
ViewtabView= tw.getChildTabViewAt(0);
TextViewtv= (TextView)tabView.findViewById(android.R.id.title);
tv.setTextSize(20);

Solution 4:

A very simple way to solve the color/contrast problem in the layout:

<TabWidget
   android:id="@android:id/tabs"
   android:background="#FF000000"
   android:padding="2dp"

This sets the background of the TabWidget to black and adds a little padding so you have contrast with the tabs against the black background. Its not perfect, but works in 1.5, 2.2, light and dark theme.

Post a Comment for "Android Tabwidget In Light Theme"