2017-12-03 7 views
-1

タブレイアウトのテキストの色を変更するためのこのコードは ですが、まったく動作しません。タブレイアウトのテキストの色を変更する方法は?

app:tabTextColorは機能せず、色が白に変わることはありません。

<android.support.design.widget.TabLayout 
     android:id="@+id/tabs" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/white" 
     app:tabIndicatorColor="@color/blue" 
     app:tabIndicatorHeight="5dp" 
     app:tabTextColor="@color/white" /> 
+0

あなたの背景は白で、あなたはあなたのtabtextcolorを白にします。 – Bek

+0

あなたは何を説明しますか?スクリーンショットをアップロードできますか? – Bek

答えて

3

あなたはTabLayoutのテキストをカスタマイズできます。

あなたがコードから、カスタムのTextView

を使用する場合は、このIDをチェックTabLayoutので、それがここにあるようIDを維持することを確認してください。この

<?xml version="1.0" encoding="utf-8"?> 
<TextView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@android:id/text1" 
    android:layout_width="match_parent" 
    android:textSize="15sp" 
    android:textColor="@color/tabs_default_color" 
    android:gravity="center" 
    android:layout_height="match_parent" 
/> 

のようなJavaコードやXMLからのTextViewを作成します。このレイアウトを膨張させ、そのTextViewにカスタムタイプフェイスを設定し、このカスタムビューをタブに追加します。

for (int i = 0; i < tabLayout.getTabCount(); i++) { 
    //noinspection ConstantConditions 
TextView tv=(TextView)LayoutInflater.from(this).inflate(R.layout.custom_tab,null) 
tv.setTextColor(customColor) 
tabLayout.getTabAt(i).setCustomView(tv); 

} 
1

それを試してみてください -

<android.support.design.widget.TabLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:tabMode="fixed" 
     app:tabGravity="fill" 
     android:background="@color/colorWhite" 
     app:tabTextColor="@color/colorBlack" 
     app:tabSelectedTextColor="@color/colorPrimary"/> 
1

使用、それはすべてのAPIレベルAPIに役立つだろう、このコード18がAPIにu.itがときtablayout役立つだろう役立つだろう26

tabLayout.setupWithViewPager(viewPager,true); 
     tabLayout.setSelected(true); 

     tabLayout.setTabTextColors(getResources().getColor(R.color.colorHintTextLight), 
        getResources().getColor(R.color.colorPrimaryTextLight)); 

<color name="colorHintTextLight">#80FFFFFF</color> 
    <color name="colorPrimaryTextLight">#FFFFFF</color> 

位置を変更します。

関連する問題