在我的Android应用程序中,我使用一个TabWidget,而无需任何特殊的自定义。我希望Android照顾特定的外观,例如,如果您将Android 1.6与2.1进行比较,则可以正常工作。通过仅使用TABWIDGET,相同的代码会导致不同形式的选项卡,因为SDK定义了如何绘制它。以下是2.1上的外观:

alt text

因此,突出显示的标签为灰色,字体为白色,您可以很好地阅读。

但是,如果您有HTC的感觉,则看起来像这样:alt text

图片不是那么好,但是只相信我是白色背景上的白色文字,这并不是那么容易阅读...

我的问题是:

1)为什么Android在白色文本上创建带有白色的TabWidget?我从不定义文本颜色或背景颜色,因此系统应该选择明智的颜色。

2)我认为其他TabWidgets在HTC Sense上看起来还不错,因为否则这将是一个很大而流行的问题。那么,为什么我的tabwidget遇到这个问题而不是其他问题。

3)如何解决此问题而不更改非感官设备上的外观?

正如我所说,我没有以任何方式自定义TabWidget。这是我的定义:

<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"
            >

因此,除了将黑色定义为我的应用程序的一般背景颜色外,也没有制作颜色或样式的定义。唯一的例外可能是我正在为TABHOST和TABWIDGET使用标准Android ID。

/编辑:这是ongreate方法中标签的定义:

th = getTabHost();
th.addTab(th.newTabSpec("shortener").setIndicator(getString(R.string.tabShortenerName),
        res.getDrawable(R.drawable.url_zip)).setContent(R.id.shortenerScrollView));

该类扩展了表格。

/编辑2:白色文本上带有白色的设备是htc Legend运行Android 2.1 BTW。

/编辑3:dream3r是对的。将targetsDK值更改为4也为我带来了诀窍(在设置为6之前)!我真的没有明白,但是我现在可以忍受。 :)

这是现在的外观:alt text

有帮助吗?

解决方案

你有 android:targetSdkVersion 放在你的 AndroidManifest.xml?

我使用示例应用程序进行了一些测试,如果我设置了同样的问题 targetSdkVersion 珍视大于 4.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top