我不知道我做了什麼,但一段時間後,我的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