2015-02-24 118 views
0

我很難改變TabWidget的顏色。我看過幾篇文章並試用過,但沒有一篇適合我。我正在嘗試將默認(藍色)顏色場景更改爲綠色。更改TabHost/TabWidget的顏色

Image of my app

我的XML代碼:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" 
android:layout_height="fill_parent" android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity" 
android:id="@+id/relativeLayout"> 

<TabHost 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@+id/tabHost" 
    android:layout_alignParentTop="true" 

    android:layout_alignParentStart="true"> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical" 
     > 

     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:clickable="true" 
      android:tabStripEnabled="false"> 

     </TabWidget> 

     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent"> 

      <LinearLayout 
       android:id="@+id/tab1" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:orientation="vertical"> 

      </LinearLayout> 

      <LinearLayout 
       android:id="@+id/tab2" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:orientation="vertical"> 
       <FrameLayout 
        android:id="@+id/listFragment" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"/> 
      </LinearLayout> 

      <LinearLayout 
       android:id="@+id/tab3" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:orientation="vertical"> 
      </LinearLayout> 

     </FrameLayout> 
    </LinearLayout> 
</TabHost> 

回答

0

使用

for(int i=0;i<mTabHost.getTabWidget().getChildCount();i++) 
{ 
    mTabHost.getTabWidget().getChildAt(i) 
          .setBackgroundColor(Color.parseColor("#00304E")); 
} 

要改變的顏色改變標籤編程是顏色的方式目前選定的標籤,

mTabHost.getTabWidget().getChildAt(mTabHost.getCurrentTab()) 
         .setBackgroundColor(Color.parseColor("#008EE8")); 
+0

@WilcovanBeijnum:你試過這個嗎? – 2015-02-25 09:34:29

+0

還沒有。我現在沒有那麼多空閒時間。我會在即將到來的星期五測試 – 2015-02-25 19:52:52

+0

謝謝!我終於搞定了。 – 2015-02-26 16:45:07