5

Ich habe seit Tagen versucht, das Holo Theme für einen benutzerdefinierten Tab Style zu überschreiben, aber meine Änderungen haben keine Wirkung.Warum überschreibt meine benutzerdefinierte 'actionBarTabStyle' den Standardstil/das Standarddesign nicht?

Hier ist meine 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>> 

Das ist mein tabselector.xml ist

<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> 

Ich habe die Tabs hinzugefügt mit TabHost in meiner Tätigkeit und das Layout sieht aus wie dieses

<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> 

Ich habe die Beispiele aus der Android Developer Page

gefolgt

Meine Registerkarten sehen immer noch gleich aus. Meine Registerkartenindikatoren sollten meine benutzerdefinierte rosa Farbe sein. Es gibt jedoch keine Veränderung, sie sind immer noch blau.

Dinge zu beachten:

  1. Meine Manifest-Datei verweist auf das aktualisierte Thema in meiner Anwendung Tags
  2. Mein styles.xml in jedem Wert Ordner aktualisiert (Werte, Werte-v11, Werte-v14)
  3. All dies tat, war eine Aktionsleiste oben auf meiner Anwendung mit meinem ic_launcher Bild und Titel

Was soll ich fehlen oder falsch hinzufügen zu tun? Schätze jede Hilfe. Danke euch allen!

Antwort

5

Die Registerkarten in ActionBar verwenden ein anderes Thema als die Registerkarten in TabHost.

Alles, was Sie tun müssen, ist android:actionBarTabStyle zu android:tabWidgetStyle zu ändern.

Voll Beispiel

<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> 

Obwohl android:tabLayout ist kein öffentliches Attribut (daher der *). Google würde daher nicht empfehlen, den Stil so zu erstellen, stattdessen würde er vorschlagen, den Indikator dynamisch zu ändern. So etwas wie folgt aus:

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)); 
    } 

Ergebnisse

Example

+0

Danke für die schnelle Antwort. Tat dies. Es hat definitiv etwas mit der Haarlinie unter den Tabs verändert ... Allerdings ist die blaue Indikatorfarbe immer noch da. Ich denke, ich kann das rosa Versteck unter dem Blau sehen ... aber es überlappt immer noch. –

+0

Mein Code in style.xml aktualisiert, um die Änderung in Ihrem Vorschlag anzuzeigen –

+0

@MarkBarrasso Ich machte eine Bearbeitung mit einem vollständigen Beispiel. – adneal