2013-06-21 80 views
0

一直在搜索這一段時間,並努力獲得任何工作。Android TabHost改變底部條的顏色

我需要將藍色底部欄的顏色更改爲十六進制值,我已更改了選項卡的背景顏色,但沒有更改TanHost上的藍色。有沒有可能改變這一點?我看到youtube使它成爲一個很好的紅色,所以它必須以某種方式可行!這是建立tabhost:

的選項卡片段通過自己的階級

// set up the tabhost 
     mTabHost = (FragmentTabHost)findViewById(android.R.id.tabhost); 
      mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent); 
      mTabHost.addTab(mTabHost.newTabSpec("event").setIndicator("Event Locations", 
        getResources().getDrawable(R.drawable.ic_event_tab)), 
        EventFragment.class, null); 
      mTabHost.addTab(mTabHost.newTabSpec("itin").setIndicator("Itinerary", 
        getResources().getDrawable(R.drawable.ic_itin_tab)), 
         ItineraryFragment.class, null); 
      mTabHost.addTab(mTabHost.newTabSpec("info").setIndicator("Kendal Info", 
        getResources().getDrawable(R.drawable.ic_info_tab)), 
        KendalInfoFragment.class, null); 

      mTabHost.getTabWidget().setBackgroundColor(Color.RED); 

回答

0

假設過時的庫工作,因爲它總是有,因爲它應該控制的,這是我已經習慣了顏色的程序我的標籤。我剛纔設置的背景中的代碼如下,因爲它是不是在XML direcly訪問:

TabWidget tabs = (TabWidget)getTabWidget();    
     for (int i = 0; i<tabs.getChildCount(); i++) { 
      RelativeLayout tab = (RelativeLayout) tabs.getChildAt(i); 
      tab.setBackgroundDrawable(this.getResources().getDrawable(R.drawable.tabindicator)); 

的tabindicator繪製如下:

<?xml version="1.0" encoding="utf-8" ?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
<!-- Non focused states --> 
<item android:state_focused="false" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/tab_unselected" /> 
<item android:state_focused="false" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_selected" /> 
<!-- Focused states --> 
<item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/tab_focus" /> 
<item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_focus" /> 
<!-- Pressed --> 
<item android:state_selected="true" android:state_pressed="true" android:drawable="@drawable/tab_press" /> 
<item android:state_pressed="true" android:drawable="@drawable/tab_press" /> 
</selector> 

的可繪製只是9塊圖像與顏色,雖然你可能能夠使用標準顏色獲得類似的效果。

OR

Links1 Link2