2016-10-16 2 views
0

안녕하세요 그냥 제목이 제안하는 것처럼 간단해야하지만 슬프게도 나를 위해 작동하지 않습니다, 난 아무것도 onTabSelected 같은 멋진 찾고 아니에요 테마를 기반으로 전체 위젯의 색상을 설정하고 싶습니다. 지금 다음을 수행하려고합니다. 올바른지 잘 모르지만 작동하지 않는지 확인하십시오.안드로이드 어떻게 스타일이나 테마에서 탭 색상을 변경할 수 있습니까

그것이지만, 내가 노력 두 번째 방법은 기쁨 없었다으로

<item name="tabBackground">@color/colorPinkPrimary</item> 

필요하지만이 방법과도 일에 내 주제에이 추가 시도한 첫 번째 방법은 단지 내 테마에 직접 추가하는 것이 었습니다 ~까지 다른 테마를

<style name="CustomTabLayoutStylePink" parent="Base.Widget.Design.TabLayout"> 
    <item name="tabSelectedTextColor">@color/selected_textPink</item> 
    <item name="tabIndicatorColor">@color/colorPinkAccent</item> 
    <item name="tabTextAppearance">@style/CustomTabTexStylePink</item> 
    <item name="tabBackground">@color/colorPinkPrimary</item> 
</style> 

를 추가하고이 같은 내 테마에서 그것을 참조하는 작업을 수행

<item name="android:tabWidgetStyle">@style/CustomTabLayoutStylePink</item> 

하나를 (단지 내가이 모범 사례 또는 가능한 경우 잘 모릅니다 반복하는, 그것은 바로 보았다)

<item name="android:background">@color/colorPinkPrimary</item> 

하지만이 또한도 환경 활동 textviews 및 아래로 내 전체 응용 프로그램에서 모든보기 위해 일하는 사람이 여기

를 나를 도울 수 등

답변

1

tabBackground은 스타일에 포함되지 않고 XML 파일에 있어야합니다.

<android.support.design.widget.TabLayout 
    ... 
    app:tabBackground="@color/colorPinkPrimary" 
    ... 
/> 
+0

알았어. 그런 식으로 할 수는 있지만 알아서 할 수 있지만 테마로 사용하면 사용자에게 줄 수 있습니다. 옵션을 사용하여 테마를 선택하고 색상을 변경하려면 프로그래밍 방식으로 변경해야합니다. 이 주제를 기반으로하는 e –

1

내가 대신 선택 적용 할 것을 테마 기록하는 우선 순위를 설정하고 어떤 테마에 따라 살아야이

private void setupTabBackground(){ 

    SharedPreferences sharedPreferences = PreferenceManager 
      .getDefaultSharedPreferences(getApplicationContext()); 
    // Create a new boolean and preference and set it to true 
    prefThemeString = sharedPreferences.getString("THEME SELECTED","BLUE"); 
    switch (prefThemeString){ 
     case "BLUE": 
      tabLayout.setBackgroundColor(getResources().getColor(R.color.colorPrimaryBlue)); 
      break; 
     case "PINK": 
      tabLayout.setBackgroundColor(getResources().getColor(R.color.colorPinkPrimary)); 
      break; 
    } 

} 
처럼 따라 탭 색상 수 없었다 원하는 것을 너무 좋아

이 활동에는 공유 환경 설정 수신기가 있어야한다고 생각하지만 나중에 해결할 수 있습니다.

관련 문제