2017-12-03 13 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의 텍스트를 사용자 정의 할 수 있습니다.

이 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" 
/> 

같은 자바 코드에서 텍스트 뷰 또는 XML 만들기 이 레이아웃을 팽창시키고 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> 

위치를 변경하십시오.