Android: Highlighted tab of TabWidget not readable on HTC Sense
Asked Answered
G

1

1

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:

alt text

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: alt text

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 changing 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: alt text

Gambrill answered 5/9, 2010 at 21:10 Comment(2)
Show us how you are defining the tabs (e.g., setIndicator()).Ceja
Added the definition of the tabs. I just pass the tab name, the icon and the content it should load for this tab.Gambrill
T
4

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.

Tericaterina answered 5/9, 2010 at 21:11 Comment(2)
Yeah, I do! I have set the target to 6 and the minSdk to 3. I will check why exactly I set such a high target, maybe it's not necessary anymore (there have been classes that I specifically used if the user was on a higher SDK, but maybe I don't need it anymore). Thanks for pointing this out, I will give it a try.Gambrill
Worth noting that this white-on-white problem is a defect in the HTC 2.1 implementation. Nice workaround by @dream3r; setting targetSdkVersion to 4 causes Android to enable the compatibility pack on 2.1 devices, which overrides the HTC tab implementation with something that works.Chrissa

© 2022 - 2024 — McMap. All rights reserved.