2014-11-17 3 views
71

Symbolleiste Hintergrund ist dunkel, ich möchte Text und zurück Pfeil weiß sein. Ich habe versucht, zu folgen, aber es funktioniert nicht.So stellen Sie Symbolleisten-Text und Pfeilfarbe zurück

<style name="Theme.MyTheme" parent="Theme.AppCompat.Light.NoActionBar"> 

     <item name="colorPrimary">@color/blue</item> 
     <item name="colorPrimaryDark">@color/blue_darker</item> 
     <item name="colorAccent">@color/purple</item> 
     <!-- item name="android:textColorPrimary">@color/white</item--> // I don't want to set this, changes everywhere. 
     <item name="android:textColorSecondary">@color/white</item> 
     <item name="android:toolbarStyle">@style/AppTheme.ToolbarStyle</item> 
     <item name="toolbarStyle">@style/AppTheme.ToolbarStyle</item> 

     <item name="drawerArrowStyle">@style/AppTheme.DrawerArrowStyle</item> 

    </style> 

    <style name="AppTheme.ToolbarStyle" parent="Base.Widget.AppCompat.Toolbar"> 
     <!--<item name="actionOverflowButtonStyle">@style/AppTheme.OverflowButtonStyle</item>--> 
     <item name="android:textColor">@color/white</item> // doesn't work 
     <item name="titleTextAppearance">@style/TextAppearance.AppCompat.Widget.ActionBar.Title.Inverse</item> 
     <item name="android:titleTextAppearance">@style/TextAppearance.AppCompat.Widget.ActionBar.Title.Inverse</item> 
     <item name="subtitleTextAppearance">@style/TextAppearance.Widget.AppCompat.Toolbar.Subtitle</item> 
    </style> 
+6

Try' App hinzufügen Zurück Pfeil und Text wird weiß sein, wie @yubarajpoudel sagte. – 1111161171159459134

Antwort

103

Wahrscheinlich sind Sie von den falschen Eltern erstreckt. Wenn nicht, können Sie versuchen, das style Layout direkt zum toolbar hinzuzufügen, wenn Sie die Einstellungen des Themas überschreiben möchten.

In der Symbolleiste Layout:

<android.support.v7.widget.Toolbar 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:minHeight="?attr/actionBarSize" 
     app:theme="@style/ToolBarStyle" 
     app:popupTheme="@style/ToolBarPopupStyle" 
     android:background="@color/actionbar_color" /> 

In Ihrem Stile:

<!-- ToolBar --> 
    <style name="ToolBarStyle" parent="Theme.AppCompat"> 
     <item name="android:textColorPrimary">@android:color/white</item> 
     <item name="android:textColorSecondary">@android:color/white</item> 
     <item name="actionMenuTextColor">@android:color/white</item>  
     <item name="actionOverflowButtonStyle">@style/ActionButtonOverflowStyle</item> 
     <item name="drawerArrowStyle">@style/DrawerArrowStyle</item> 
</style> 
+4

gibt Fehler beim Hinzufügen dieses Stils zu 'styles.xml' Datei –

+1

Sie brauchen nicht die Schublade ArrowStyle Teil, um die Frage zu beantworten –

5
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:id="@+id/toolbar" 
android:layout_width="match_parent" 
android:layout_height="?attr/actionBarSize" 
android:background="@color/actionBar" 
app:titleTextAppearance="@style/ToolbarTitleText" 
app:theme="@style/ToolBarStyle"> 

<TextView 
    android:id="@+id/title" 
    style="@style/ToolbarTitleText" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" 
    android:text="hh"/> 

<!-- ToolBar --> 
<style name="ToolBarStyle" parent="Widget.AppCompat.Toolbar"> 
    <item name="actionMenuTextColor">#ff63BBF7</item> 
</style> 

Nutzung App: theme = "@ style/ToolBarStyle"

Reference resources:http://blog.csdn.net/wyyl1/article/details/45972371

+1

Bitte erklären Sie Ihre Antworten, nur Buchung Code ist nicht sehr klar für die Beantwortung einer Frage. – SuperBiasedMan

0

an der Rückseite Symbol der Symbolleiste ändern drawable Sie diese verwenden können:
die <item name="toolbarStyle">@style/ToolbarStyle</item> in Ihrem Thema hinzufügen.
Und hier ist die ToolbarStyle selbst:

<style name="ToolbarStyle" parent="Widget.AppCompat.Toolbar"> 
    <item name="navigationIcon">@drawable/ic_up_indicator</item> 
</style> 
84

Fügen Sie den folgenden als toolbar.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.Toolbar 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/toolbar" 
    android:layout_height="wrap_content" 
    android:layout_width="match_parent" 
    android:fitsSystemWindows="true" 
    android:minHeight="?attr/actionBarSize" 
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
    android:background="?attr/colorPrimary"> 

</android.support.v7.widget.Toolbar> 

dann im Layout, wo Sie

<include layout="@layout/toolbar"/> 

+7

Ja, funktioniert! Besonders "app: theme =" @ style/ThemeOverlay.AppCompat.Dark.ActionBar "'. – 1111161171159459134

+1

Sollte '' –

1

Try Genießen benötigt eine Menge Methoden, in der niedrigen Version der API, ein fe asible Methode ist <item name="actionMenuTextColor">@color/your_color</item> und verwenden Sie nicht den Android-Namespace

ps:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
    <!-- Customize your theme here. --> 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorAccent</item> 

    <!-- change the textColor --> 
    <item name="actionMenuTextColor">@color/actionMenuTextColor</item> 
</style> 
4
<android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimaryDark" 
      app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 
</android.support.design.widget.AppBarLayout> 
1

Ich benutzte Platzhalter so einfach folgen zusammen, wie Sie immer noch das Erbe der ursprünglichen Stil behalten wollen könnte.

Vor

<android.support.v7.widget.Toolbar 
    android:id="@+id/toolBar" 
    android:layout_width="match_parent" 
    android:layout_height="?attr/actionBarSize" 
    android:background="?attr/colorPrimary" 
    android:elevation="4dp" 
    android:theme="@style/{{originalBaseStyle}}" 
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/> 

Nach:

styles.xml

<style name="{{yourToolbarStyle}}" parent="{{originalBaseStyle}}"> 
    <item name="android:textColorPrimary">@android:color/white</item> 
    <item name="android:textColorSecondary">@android:color/white</item> 
    <item name="actionMenuTextColor">@android:color/white</item> 
    <item name="actionOverflowButtonStyle">@style/ActionButtonOverflowStyle</item> 
    <item name="drawerArrowStyle">@style/DrawerArrowStyle</item> 
</style> 

Deshalb

<android.support.v7.widget.Toolbar 
    android:id="@+id/toolBar" 
    android:layout_width="match_parent" 
    android:layout_height="?attr/actionBarSize" 
    android:background="?attr/colorPrimary" 
    android:elevation="4dp" 
    android:theme="@style/{{yourToolbarStyle}}" 
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/> 
24

Innerhalb Aktivität, können Sie

Wenn Sie lieben, xml für beide Titelfarbe & zurück Pfeil weiß zu wählen, fügen Sie einfach diesen Stil in style.xml hinzu.

<style name="ToolBarStyle" parent="Theme.AppCompat"> 
    <item name="android:textColorPrimary">@android:color/white</item> 
    <item name="android:textColorSecondary">@android:color/white</item> 
    <item name="actionMenuTextColor">@android:color/white</item> 
</style> 

Und Symbolleiste wie folgt aussehen:

<android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     app:theme="@style/ToolBarStyle" 
     android:layout_height="?attr/actionBarSize" 
    /> 
+0

dies funktioniert ... – kelvincer

5

ich eine viel einfachere fix gefunden haben: einfach diesen Code in Ihre Symbolleiste in xml hinzufügen

<Toolbar 
    android:id="@+id/toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:minHeight="?android:attr/actionBarSize" 
    android:background="?android:attr/colorPrimary" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
    android:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
    android:titleTextColor="#ffffffff" /> 
+1

beachten Sie, dass dies erfordert api> 23 –

+0

@VygintasB true –

0

Versuchen Sie dies auf Ihre XML-Datei

<android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     app:titleTextColor="@color/colorAccent" 
     app:theme="@style/ToolbarColoredBackArrow" 
     app:subtitleTextColor="@color/colorAccent" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     app:popupTheme="@style/AppTheme.PopupOverlay" /> 

Und das ist y unsere Datei Colors.xml

<color name="colorAccent">YOUR_COLOR</color> 
+0

Bitte teilen Sie uns mit, was in der App war: theme = "@Style/ToolbarColoredBackArrow" – Simon

0

Wenn die neueste Version von Android Studio 3.0 verwenden und Ihre Aktivität Klassen zu erzeugen, ändern Sie in Ihren Stilen Dateien dies:

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" /> 

Um dies:

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.ActionBar" /> 
0

diese Methode hat mir geholfen. theme = "@ style/ThemeOverlay.AppCompat.Dark.ActionBar" `zu` `;:

<style name="AppTheme" parent="Theme.AppCompat.Light"> 
     <item name="colorPrimary">@color/primary</item> 
     <item name="colorPrimaryDark">@color/primaryDark</item> 
     <item name="colorAccent">@color/highlightRed</item> 
     <item name="actionBarTheme">@style/ToolbarStyle</item> 
</style> 

<style name="ToolbarStyle" parent="Widget.AppCompat.ActionBar"> 
     <item name="android:textColorPrimary">@color/white</item> 
</style> 
Verwandte Themen