5

커스텀 탭 스타일의 Holo 테마를 덮어 쓰려고 며칠이나 노력했지만, 변경 사항이 적용되지 않습니다.내 'actionBarTabStyle'사용자 정의가 기본 스타일/테마를 덮어 쓰지 않는 이유는 무엇입니까?

다음은이

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 

    <!-- Non focused states --> 
    <item android:drawable="@drawable/tab_unselected_holo" android:state_focused="false" android:state_pressed="false" android:state_selected="false"/> 
    <item android:drawable="@drawable/tab_selected_holo" android:state_focused="false" android:state_pressed="false" android:state_selected="true"/> 

    <!-- Focused states --> 
    <item android:drawable="@drawable/tab_unselected_focused_holo" android:state_focused="true" android:state_pressed="false" android:state_selected="false"/> 
    <item android:drawable="@drawable/tab_selected_focused_holo" android:state_focused="true" android:state_pressed="false" android:state_selected="true"/> 

    <!-- Pressed --> 
    <!-- Non focused states --> 
    <item android:drawable="@drawable/tab_unselected_pressed_holo" android:state_focused="false" android:state_pressed="true" android:state_selected="false"/> 
    <item android:drawable="@drawable/tab_selected_pressed_holo" android:state_focused="false" android:state_pressed="true" android:state_selected="true"/> 

    <!-- Focused states --> 
    <item android:drawable="@drawable/tab_unselected_pressed_holo" android:state_focused="true" android:state_pressed="true" android:state_selected="false"/> 
    <item android:drawable="@drawable/tab_selected_pressed_holo" android:state_focused="true" android:state_pressed="true" android:state_selected="true"/> 

</selector> 

내가 내 활동에 TabHost를 사용하여 탭을 추가 한 내 tabselector.xml 내 styles.xml

<!-- the theme applied to the application or activity --> 
<style name="CustomActionBarTheme" parent="@android:style/Theme.Holo"> 
    <item name="android:tabWidgetStyle">@style/MyActionBarTabs</item> 
</style> 

<!-- ActionBar tabs styles --> 
<style name="MyActionBarTabs" parent="@android:style/Widget.Holo.ActionBar.TabView"> 

    <!-- tab indicator --> 
    <item name="android:background">@drawable/tabselector</item> 
</style>> 

그리고 레이아웃이

<android.support.v4.app.FragmentTabHost xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/tabhost" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

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

     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="0" 
      android:orientation="horizontal" /> 

     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="0dp" 
      android:layout_height="0dp" 
      android:layout_weight="0" /> 

     <FrameLayout 
      android:id="@+id/realtabcontent" 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" /> 
    </LinearLayout> 

</android.support.v4.app.FragmentTabHost> 
처럼 보인다

나는이 예제를 따르고있다. Android Developer Page

내 탭은 여전히 ​​동일하게 보입니다. 내 탭 표시기가 내 사용자 정의 색 분홍색으로되어 있습니다. 그러나 변화가 없으며 여전히 푸른 색입니다.

유의할 것들 :

  1. 내 매니페스트 파일 내 응용 프로그램 태그에 업데이트 된 테마를 참조
  2. 내 styles.xml은 각 값 폴더에 업데이트됩니다
  3. (값, 값-V11, 값-V14)
  4. 이 모든 짓을
  5. 내 ic_launcher 이미지와 제목 I가 없거나 잘못을하고있는 중이 야 무엇

내 응용 프로그램의 상단에 작업 표시 줄을 추가했다? 어떤 도움을 주시면 감사하겠습니다. 다들 감사 해요!

답변

5

ActionBar의 탭은 TabHost의 탭과 다른 테마를 사용합니다.

android:actionBarTabStyleandroid:tabWidgetStyle으로 변경하면됩니다.

android:tabLayout 공용 속성이 아닌

<style name="Your.Theme" parent="@android:style/Theme.Holo.Light.DarkActionBar"> 
    <item name="android:tabWidgetStyle">@style/Your.TabWidget</item> 
</style> 

<style name="Your.TabWidget" parent="@android:style/Widget.Holo.TabWidget"> 
    <item name="*android:tabLayout">@layout/your_tab_layout</item> 
</style> 

<style name="Your.Tab" parent="@android:style/Widget.Holo.ActionBar.TabView"> 
    <item name="android:background">@drawable/your_tab_indicator</item> 
    <item name="android:layout_width">0dip</item> 
    <item name="android:layout_weight">1</item> 
    <item name="android:minWidth">80dip</item> 
</style> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    style="@style/Your.Tab" 
    android:layout_height="?android:attr/actionBarSize" 
    android:orientation="horizontal" > 

    <ImageView 
     android:id="@android:id/icon" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_vertical" 
     android:visibility="gone" /> 

    <TextView 
     android:id="@android:id/title" 
     style="@android:style/Widget.Holo.ActionBar.TabText" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_vertical" 
     android:maxWidth="180dip" /> 

</LinearLayout> 

비록 전체 예 (따라서 *). Google은 이와 같은 스타일을 권장하지 않으며 표시기를 동적으로 수정하는 것이 좋습니다. 그래서,이 같은 일이 :

final TabWidget tabWidget = tabHost.getTabWidget(); 
    for (int i = 0; i < tabWidget.getTabCount(); i++) { 
     final View tab = tabWidget.getChildTabViewAt(i); 
     tab.setBackground(getResources().getDrawable(R.drawable.your_tab_indicator)); 
    } 

빠른 응답

Example

+0

감사 결과. 그거 했어. 탭 밑의 헤어 라인을 사용하여 확실히 뭔가를 바 꾸었습니다 ... 그러나 파란색 표시기 색상이 그대로 남아 있습니다. 나는 파란색 밑에 핑크색의 은신처가 보일 수 있다고 생각하지만 ... 여전히 겹쳐져있다. –

+0

내 코드를 style.xml에 업데이트하여 제안 사항을 편집하십시오. –

+0

@MarkBarrasso 전체 예제로 편집했습니다. – adneal