Android: Highlighted tab of TabWidget not readable on HTC Sense
In my Android app I use a TabWidget without any special customization. I'd like Android to take care of the specific appearance, which works fine if you compare Android 1.6 with 2.1 for example. By just using a TabWidget the same code leads to different forms of tabs because the SDK defines how to draw it. Here is how it looks on 2.1 for example:
So, the highlighted tab is gray and the font is white and you can read it quite well.
But, if you have HTC Sense, it looks like this:
The picture isn't that good, but just believe me that it's white text on white background which is not really that easy to read...
My questions are:
1) Why does Android create a TabWidget with white on white text? I never defined either the text color or the background color, so the system is supposed to chose sensible colors.
2) I assume that other TabWidgets look just fine on HTC Sense, because otherwise it would be quite a big and popular problem. So why is my TabWidget having this problem and not others.
3) How can I fix this problem without chang开发者_StackOverflow社区ing the appearance on non Sense devices?
As I said I did not customize the TabWidget in any way. Here is my definition:
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/black"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="0dp"
>
<ScrollView
android:id="@+id/shortenerScrollView"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:background="@android:color/black"
android:fadingEdge="horizontal"
>
So, besides defining black as my general background color of the app, there's no color or style defintion made. The only exception might be that I'm using standard Android ids for TabHost and TabWidget.
/Edit: Here's the defintion of the tabs in the onCreate method:
th = getTabHost();
th.addTab(th.newTabSpec("shortener").setIndicator(getString(R.string.tabShortenerName),
res.getDrawable(R.drawable.url_zip)).setContent(R.id.shortenerScrollView));
The class extends a TabActivity.
/Edit 2: The device that comes up with the white on white text is a HTC Legend running Android 2.1 btw.
/Edit 3: dream3r was right. Changing the targetSdk value to 4 did the trick for me, too (before, it was set to 6)! I don't really get it, but I can live with that for now. :)
Here's a picture of how it looks now:
Do you have android:targetSdkVersion
set in your AndroidManifest.xml?
I made some test using sample application and I have the same issue if I set targetSdkVersion
to value greater than 4
.
精彩评论