-2
A
回答
0
嘗試此,
public void onTabChanged(String tabId) {
// TODO Auto-generated method stub
for(int i=0;i<mTabHost.getTabWidget().getChildCount();i++)
{
View view = mTabHost.getTabWidget().getChildTabViewAt(i);
if (view != null) {
// get title text view
TextView textView = (TextView)view. findViewById(R.id.tab_title);
textView.setTextColor(Color.WHITE);
}
}
title.setTextColor(Color.RED);
}
+0
如何將TextView tab_title添加到TabWidget中? –
0
看看這documentation,內部onCreate()
方法以限定用於選定和未選定標籤初始背景顏色。
for(int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {
tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#8A4117"));
}
tabHost.getTabWidget().setCurrentTab(1);
tabHost.getTabWidget().getChildAt(1).setBackgroundColor(Color.parseColor("#C35817"));
貫徹OnTabChangeListener
到當前活動,然後重寫onTabChanged()
方法。在該方法中,編寫下面的代碼以定義選定選項卡和未選定選項卡的顏色。
@Override
public void onTabChanged(String tabId) {
for(int i = 0; i < tabHost.getTabWidget().getChildCount(); i++){
tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#8A4117"));
}
tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundColor(Color.parseColor("#C35817"));
}
更新
更改您標籤文字顏色:
通過XML文件:
<android.support.design.widget.TabLayout app:tabTextColor="@color/your_color" app:tabSelectedTextColor="@color/your_color"/>
通過代碼:
tabLayout.setTabTextColors( ContextCompat.getColor(context, R.color.your_unselected_tab_text_color), ContextCompat.getColor(context, R.color.your_selected_tab_text_color) );
+0
不。我想更改文字顏色,而不是標籤顏色。但我很感激你的幫助。當我選擇一個標籤時,你知道如何改變指示器的文字顏色嗎? –
相關問題
- 1. Silverlight:如何更改TreeViewItem文本顏色,當它被選中
- 2. 當它的bg顏色設置爲黑色時,UINavigationBar是白色
- 3. 當文本被截斷時更改div中的文本顏色
- 4. 當它被選中時不能改變tableviewcell的顏色
- 5. 當酒吧顏色被選中時,barplot的顏色條
- 6. 設置選中行時WPF DataGrid行的文本顏色
- 7. UIlabel文本顏色取決於漸變顏色指示器
- 8. OpenGL:設置文本顏色?
- 9. 如何設置edittext的浮動標籤文本顏色,當它不是焦點不同於edittext提示顏色?
- 10. 當QlineEdit設置背景圖像時,如何在QLineEdit中設置文本顏色
- 11. 設置帳戶同步指示器紅色(或其他顏色)
- 12. 當選中時,在TabBarController上設置不同的顏色?
- 13. Android TabHost初始選項卡的文本顏色不正確
- 14. 在tabhost設置文本 - Android
- 15. UITableViewCell backgroundColor在IB中設置,當它設置爲白色時顯示黑色
- 16. $。將背景顏色設置爲當前設置的顏色
- 17. 在StyleableTextField中設置文本顏色
- 18. 如何在選定的TextView中設置文本的顏色
- 19. 如何在Android中設置選項卡視圖指示器背景顏色
- 20. 如何在編輯時設置文本框的文本顏色
- 21. 當android:state_enabled =「false」時無法設置顏色
- 22. 在NSTextView中設置選定文本的背景顏色?
- 23. 如何在Html.Listbox中設置所選項目的文本顏色
- 24. 如何爲TabLayout.Tab設置未選中的文本顏色 - Android
- 25. 在當前瀏覽器中獲取文本選擇顏色和背景顏色
- 26. 當勾選CheckBox時,更改ListView行中的文本顏色
- 27. 刪除:從文本中懸停顏色而不設置顏色
- 28. 當我的輸入沒有被展開時給出一個顏色,當它被展開時其他顏色
- 29. 當選擇框集中時設置多個選擇框選項的顏色
- 30. 如何設置ActionItem文本的顏色
請提供一些代碼,以便我們可以幫助您。 – MohammedAlSafwan