我在我的Android应用程序中使用选项卡,在HTC Sense手机上运行应用程序时遇到了这个问题:
Android:TabWidget的突出显示选项卡在HTC Sense上无法读取
建议那里的解决方案(将android:targetSdkVersion设置为4)不能解决我的问题,也不想将目标sdk设置为4.
我已经尝试解决这个问题,我创建了自己的标签小部件样式,并修改了文本颜色.问题是当我使用自己的风格时没有明显的区别; 即样式似乎没有应用于选项卡.
这是主要活动的代码,包含选项卡:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tab);
tabHost = getTabHost();
tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("Tab 1").setContent(new Intent(this, Tab1.class)));
tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("Tab 2").setContent(new Intent(this, Tab2.class)));
tabHost.setCurrentTab(0);
}
Run Code Online (Sandbox Code Playgroud)
这是我的tab.xml.请注意,我已将MyTabStyle指定为TabWidget的样式:
<?xml version="1.0" encoding="utf-8"?>
<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">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<TabWidget
style="@style/MyTabStyle"
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="5dp" />
</LinearLayout>
</TabHost>
Run Code Online (Sandbox Code Playgroud)
这是我对MyTabStyle的定义,我在res/values/styles.xml中定义了它:
<style name="MyTabStyle" parent="@android:style/TextAppearance.Widget.TabWidget">
<item name="android:textColor">#5DFC0A</item>
</style>
Run Code Online (Sandbox Code Playgroud)
为什么我的应用程序中没有MyTabStyle中的任何更改?解决HTC Sense中选定选项卡上不可见文本的任何其他解决方案?
更新2011-06-02
通过使用选项卡上的文本实际上是TextViews的知识,我设法以一种hacky方式解决了这个问题.将以下方法添加到您的活动中:
private void setTabColor(TabHost tabHost) {
try {
for (int i=0; i < tabHost.getTabWidget().getChildCount();i++) …Run Code Online (Sandbox Code Playgroud)