2014-12-20 33 views
2

我目前正在研究實現Appcompat工具欄的應用程序。 現在我的問題是,如果我選擇Light Actionbar作爲基礎,菜單是白色的,標題是黑色的。 我想都是白色的。 如果我更改爲Dark Actionbar作爲底座,則文本爲白色,但菜單變黑。工具欄 - 燈光標題和燈光菜單

以下是截圖:

enter image description here

我只想標題文本顏色設置爲白色。

這裏是我的styles.xml:

<resources> 

<!-- Base application theme. --> 
<style name="AppTheme" parent="Theme.AppCompat.Light"> 
    <item name="windowActionBar">false</item> 
    <item name="colorPrimary">@color/primary</item> 
    <item name="colorAccent">@color/accent</item> 
    <item name="colorPrimaryDark">@color/primary_dark</item> 
</style> 


</resources> 

而這裏的toolbar.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:minHeight="?attr/actionBarSize" 
    android:background="?attr/colorPrimary"/> 

我希望你能幫助我。 在此先感謝!

回答

2

你只需要在你的style.xml下面添加樣式選擇它永遠顏色,你想要的,請更換顏色按您的要求:

<style name="MyToolbarStyle" parent="ThemeOverlay.AppCompat.ActionBar"> 
    <!-- Used to for the title of the Toolbar --> 
    <item name="android:textColorPrimary">#fff</item> 
    <!-- Used to for the title of the Toolbar when parent is Theme.AppCompat.Light --> 
    <item name="android:textColorPrimaryInverse">#fff</item> 
    <!-- Used to color the text of the action menu icons --> 
    <item name="android:textColorSecondary">#fff</item> 
    <!-- Used to color the overflow menu icon --> 
    <item name="actionMenuTextColor">#fff</item> 
    <!-- Color of the Toolbar --> 
    <item name="android:background">#455a64</item> 
</style> 

,並確保這個屬性添加到工具欄:

app:theme="@style/MyToolbarStyle" 
+0

感謝。我爲'android:textColorSecondary'設置了灰色(用於箭頭,設置等元素)。正如我想要的那樣,還將「父」更改爲「AppTheme」,然後白色變成灰色。 – CoolMind

11

添加到您的工具欄元素

<!-- dark toolbar --> 
<item name="android:theme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item> 
<!-- light popup --> 
<item name="popupTheme">@style/ThemeOverlay.AppCompat.Light</item>