2013-07-15 111 views
0

我想將tabhost的默認藍色更改爲紅色。更改tabhost風格android

<style name="AppTheme" parent="android:Theme.Light.NoTitleBar"> 
      <item name="android:tabWidgetStyle">@drawable/tab_indicator_holo</item> 
      </style> 

tab_indicator_holo.xml

<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_holo" /> 
    <item android:state_focused="false" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_selected_holo" /> 

    <!-- Focused states --> 
    <item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/tab_unselected_focused_holo" /> 
    <item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_selected_focused_holo" /> 

    <!-- Pressed --> 
    <!-- Non focused states --> 
    <item android:state_focused="false" android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/tab_unselected_pressed_holo" /> 
    <item android:state_focused="false" android:state_selected="true" android:state_pressed="true" android:drawable="@drawable/tab_selected_pressed_holo" /> 

    <!-- Focused states --> 
    <item android:state_focused="true" android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/tab_unselected_pressed_holo" /> 
    <item android:state_focused="true" android:state_selected="true" android:state_pressed="true" android:drawable="@drawable/tab_selected_pressed_holo" /> 
</selector> 

但標籤樣式不應用於tabhost。默認的藍色不會變爲紅色。

我得到這個

enter image description here

任何意見或建議,請。

+0

'安卓tabWidgetStyle'應指向延長'Widget.TabWidget'(這反過來會覆蓋它的標籤欄屬性之一指向你有'tab_indicator_holo.xml'繪製風格)。 – Luksprog

回答

5

你可能已經找到了答案,但對於那些可能面臨同樣問題的人,這就是我所做的。

  1. 轉到custom holo theme並將tabwedget設置爲yes並選擇首選顏色。

  2. 下載zip文件,複製到我的項目中。

  3. 添加到tabadapter與充氣tab_indicator_holo創建的視圖。

View mIndicator = inflater.inflate(R.layout.tab_indicator_holo, mTabHost.getTabWidget(), false); 
    TextView title1 = (TextView) mIndicator.findViewById(android.R.id.title); 

    title1.setText("TAB1"); 

    mTabsAdapter.addTab(mTabHost.newTabSpec("TAB1").setIndicator(mIndicator), FRAGMENT1.class, null); 

    View mIndicator2 = inflater.inflate(R.layout.tab_indicator_holo,  mTabHost.getTabWidget(), false); 
    TextView title2 = (TextView) mIndicator2.findViewById(android.R.id.title); 

    title2.setText("TAB2"); 
    mTabsAdapter.addTab(mTabHost.newTabSpec("TAB2").setIndicator(mIndicator2), FRAGMENT2.class, null);
+0

謝謝!這終究正是我所需要的。真棒! – Zach

+0

NyanLH,你能完成你的代碼示例嗎?哪個功能添加到? inflater,mTabsAdapter從哪裏來? – Gavriel