2017-01-29 7 views
0

Как изменить цвет отображения экрана макета виджета вкладки? В настоящее время он белый. Я хочу изменить его на синий.цвет фона вкладки виджет

<?xml version="1.0" encoding="utf-8"?> 
<TabHost android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android" xmlns:ads="http://schemas.android.com/apk/res-auto"> 
    <LinearLayout android:orientation="vertical" android:id="@id/mainLayout" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ff2356bf" > 
     <FrameLayout android:layout_width="0.0dip" android:layout_height="0.0dip" android:layout_weight="0.0" /> 
     <TabWidget android:orientation="horizontal" android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="0.0" /> 
     <android.support.v4.view.ViewPager android:id="@id/pager" android:layout_width="fill_parent" android:layout_height="0.0dip" android:layout_weight="1.0" /> 
     <LinearLayout android:layout_gravity="center" android:orientation="vertical" android:id="@id/BannerLayout" android:paddingBottom="2.0dip" android:layout_width="fill_parent" android:layout_height="wrap_content"> 
      <com.google.android.gms.ads.AdView android:layout_gravity="center_horizontal" android:id="@id/adView" android:layout_width="fill_parent" android:layout_height="wrap_content" ads:adSize="BANNER" ads:adUnitId="@string/banner" /> 
     </LinearLayout> 
    </LinearLayout> 
</TabHost> 

enter image description here

+0

Возможный дубликат [стиль оформления текста в стиле Android tabhost] (http://stackoverflow.com/questions/22533061/android-tabhost-change-text-color-style) –

ответ

0

От https://stackoverflow.com/a/38835247/4758255@will-molter Ответ:

Это на самом деле может быть сделано с помощью темы XML. TabWidget использует android:textColorPrimary для выбранной вкладки и android:textColorSecondary для невыбранных. Таким образом, вы можете добиться изменения цвета текста, как это:

В styles.xml:

<style name="TabWidgetTheme" parent="AppTheme"> 
    <item name="android:textColorPrimary">@color/your_primary_color</item> 
    <item name="android:textColorSecondary">@color/your_secondary_color</item> 
</style> 

В макете:

<TabHost 
    android:layout_height="match_parent" 
    android:layout_width="match_parent" 
    android:theme="@style/TabWidgetTheme"/> 

Обратите внимание, что android:theme не должен быть непосредственно в TabWidget сам, но содержащий TabHost или аналогичный.