我不知道我做了什么,但一段时间后,我的TabWidget有白色的标签,看起来非常漂亮。我从来没有在我的项目中设置主题或背景/前景色。下次我编译它时,它又回到了灰色的标签页。我的应用程序使用默认的黑暗主题。即使我将应用程序主题设置为亮起,选项卡仍然是灰色的。显然这是改变标签颜色的其他内容。有人知道怎么做吗?TabWidget白色前景色?
回答
我由于Android 1.6的灯光主题(选项卡指示灯文字为白色)中的错误而导致出现问题。我能覆盖默认的主题如下:
- 我创建了一个从默认的主题,继承了自定义主题:
styles.xml
:
<style name="MyTheme" parent="@android:style/Theme.Light">
<item name="android:tabWidgetStyle">@style/LightTabWidget</item>
</style>
<style name="LightTabWidget" parent="@android:style/Widget.TabWidget">
<!-- set textColor to red, so you can verify that it applied. -->
<item name="android:textColor">#f00</item>
</style>
然后我申请的是主题通过将android:theme="@style/MyTheme"
添加到我的AndroidManifest.xml
的<application />
元素中,将其添加到我的应用程序中。
thanx史蒂夫,它帮助我,你让我的生活 – 2010-09-21 10:34:43
检查这个答案我的:Background in tab widget ignore scaling
您也可以参考android.graphics.drawable
包
在你的代码,你可以这样设置你的标签背景:
tabHost.getTabWidget().getChildAt(0).setBackgroundResource(
android.R.color.white);
这使得标签背景无论如何都是黑色的。 – Monstieur 2010-03-31 04:12:54
public void onCreate(Bundle savedInstanceState)
`tabHost = getTabHost();
tabHost.setOnTabChangedListener(this);
tabHost.setCurrentTab(0);
setTabColor();`
比在听者:
公共无效onTabChanged(字符串tabId){ setTabColor();
最后的功能,设置前景色和背景太:
public void setTabColor() {
// set foreground color:
for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {
RelativeLayout rl = (RelativeLayout) tabHost.getTabWidget().getChildAt(i);
ImageView imageView = (ImageView) rl.getChildAt(0);// change it if you want it
TextView textView = (TextView) rl.getChildAt(1);//
textView.setTextColor(Color.parseColor("#FFFFFF"));
}
// set background color:
for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {
tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#010101")); // unselected
}
tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundColor(Color.parseColor("#121288")); // selected
}
在onCreated():
tabHost.setCurrentTab(0);
// Set tabs text color to white:
TabWidget tabWidget = tabHost.getTabWidget();
int whiteColor = getResources().getColor(R.color.white);
int someOtherColor = getResources().getColor(R.color.someOtherColor);
for(int i = 0; i < tabWidget.getChildCount(); i++){
View tabWidgetChild = tabWidget.getChildAt(i);
if(tabWidgetChild instanceof TextView){
((TextView) tabWidgetChild).setTextColor(whiteColor);
} else if(tabWidgetChild instanceof Button){
((Button) tabWidgetChild).setTextColor(whiteColor);
} else if(tabWidgetChild instanceof ViewGroup){
ViewGroup vg = (ViewGroup)tabWidgetChild;
for(int y = 0; y < vg.getChildCount(); y++){
View vgChild = vg.getChildAt(y);
if(vgChild instanceof TextView){
((TextView) vgChild).setTextColor(whiteColor);
}
}
vg.setBackgroundColor(someOtherColor);
}
}
- 1. 根据背景制作前景色黑色或白色
- 2. 白色背景()
- 3. 纯白色背景色
- 4. 如何在OpenCV中创建背景黑色和前景白色?
- 5. 颜色TabWidget
- 6. Android TabWidget设置背景颜色错误
- 7. Textfield背景色白色,活动灰色背景色
- 8. PHPExcel白色背景
- 9. iOS褪色白色背景上的强烈白色文字?
- 10. 在白色背景上显示白色图像为灰色:Android
- 11. Pascal - 将背景设置为白色(不是灰色,纯白色)
- 12. 设定背景色为白色包含白色
- 13. DataGridTextColumn前景色
- 14. LongListSelector前景色
- 15. 如何使所有控件的前景色默认为白色
- 16. 白色背景上的div为白色或透明CSS背景色?
- 17. 不透明的白色背景与rgba在白色背景显示灰色?
- 18. Android - 灰色背景而不是白色
- 19. Imagick - 使黑色背景变成白色
- 20. CardView背景颜色始终为白色
- 21. 白色背景与MD颜色
- 22. ListView背景颜色不是白色
- 23. 背景色透明显示为白色
- 24. 做一个背景白色
- 25. UIWebView背景总是白色
- 26. 图片GD - 白色背景
- 27. 白色背景上的ProgressBar
- 28. 白色背景闪烁
- 29. Python OpenCV纯白色背景
- 30. JTextPane和前景色
你也许在两个不同版本的平台测试?标签样式在2.0中更改。另外,如果你可以发布截图,采用'DDMS',这将非常有帮助。 – 2010-03-30 07:55:13
啊,是的。它来自编译1.6。有没有办法为2.0+手动设置相同的颜色? – Monstieur 2010-03-31 04:05:29
我有这个问题,并确定它是AndroidManifest.xml中的'targetSdkVersion'属性导致它改变了我。 – 2010-07-02 14:05:26