我不知道我做了什么,但一段时间后,我的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. 颜色TabWidget
- 5. Android TabWidget设置背景颜色错误
- 6. Textfield背景色白色,活动灰色背景色
- 7. iOS褪色白色背景上的强烈白色文字?
- 8. 设定背景色为白色包含白色
- 9. 白色背景上的div为白色或透明CSS背景色?
- 10. ListView背景颜色不是白色
- 11. 背景色透明显示为白色
- 12. CardView背景颜色始终为白色
- 13. 做一个背景白色
- 14. 白色背景上的ProgressBar
- 15. Python OpenCV纯白色背景
- 16. AppBarButton的前景色
- 17. Android微调:白色背景上的白色文字
- 18. swift中的白色背景图像上的白色文字
- 19. 跟踪白色背景中的白色球(Python/OpenCV)
- 20. ImageMagick白色透明背景,同时保持白色对象
- 21. 更改TabHost/TabWidget的颜色
- 22. 设置TabItem前景色还设置TabControl前景色
- 23. 灰色背景颜色列表项目而不是白色
- 24. 给定背景颜色,黑色或白色文本?
- 25. Sass:混合rgba(白色,0.5)和纯色背景色
- 26. .net前景色的调色板参考?
- 27. 白色不是白色
- 28. .jpg img白色背景与html页面发生冲突白色背景
- 29. 指定的前景色无效:“default”。预计的(黑色,红色,绿色,黄色,蓝色,品红色,青色,白色)
- 30. 如何在grabcut算法后将生成的前景颜色更改为白色?
你也许在两个不同版本的平台测试?标签样式在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