2015-02-24 78 views
5

我正在使用新的android appcompat工具欄。我需要爲漢堡圖標和後退箭頭圖標設置相同的自定義顏色。使用drawerArrowStyle允許我改變漢堡圖標,但不是箭頭。這個問題只在棒棒糖設備上,任何棒棒糖都可以。Android:無法更改後退箭頭導航圖標的顏色

Burger

Arrow

下面是代碼:

工具欄:

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

Style.xml:

<style name="Theme.Base" parent="Theme.AppCompat.Light"> 
    <!-- All customizations that are NOT specific to a particular API-level can go here. --> 
    <item name="windowActionBar">false</item> 
    <item name="android:windowNoTitle">true</item> 
    <!-- colorPrimary is used for the default action bar background --> 
    <item name="colorPrimary">@color/my_primary</item> 
    <!-- colorPrimaryDark is used for the status bar --> 
    <item name="colorPrimaryDark">@color/black</item> 
    </style> 

    <style name="My.Theme" parent="Theme.Base"> 
     <item name="drawerArrowStyle">@style/DrawerArrowStyle</item> 
    </style> 

    <style name="My.Toolbar" parent="Theme.AppCompat.NoActionBar"> 
     <!-- color of the title text in the Toolbar, in the Theme.AppCompat theme: --> 
     <item name="android:textColorPrimary">@color/my_actionbartext</item> 

     <!-- necessary to support older Android versions.--> 
     <item name="actionMenuTextColor">@color/my_actionbartext</item> 

     <item name="android:textColorSecondary">@color/my_actionbartext</item> 
    </style> 

    <style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle"> 
      <item name="color">@color/my_actionbartext</item> 
    </style> 

我試過使用here的解決方案,但沒有奏效。任何人有任何想法?

+0

可能重複[如何改變新材料題材後退箭頭的顏色?(http://stackoverflow.com/questions/26788464/how-to-change-color-of-the- back-arrow-in-the-new-material-theme) – Daniel 2015-05-19 15:58:19

回答

1

爲這個問題的正確解決方案的路徑,我發現here

但這項工作仍然沒有100%的原因是我們使用DrawerLayout的。我的同事寫了一個很好的職位上解決here

+0

查看我的答案解答100% – Daniel 2015-05-10 12:02:04

+0

偉大的鏈接,我只需要改變主題自己設置它正確,但這提出了一點,當一個抽屜被使用,它對drawables有一個有趣的效果。 – Silmarilos 2015-09-17 22:59:04

2

只是這樣做在你的活動/片段:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) 
      getSupportActionBar().setHomeAsUpIndicator(getResources().getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha, null)); 
     else 
      getSupportActionBar().setHomeAsUpIndicator(getResources().getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha)); 

    getSupportActionBar().setDisplayHomeAsUpEnabled(true); 
1

我也不能回更新升級到23.2.0支持庫後箭頭按鈕

<style name="ThemeOverlay.MyApp.ActionBar" parent="ThemeOverlay.AppCompat.ActionBar"> 
     <item name="android:textColorPrimary">@color/white</item> 
     <item name="android:textColorSecondary">@color/white</item> 
    </style> 
0

這是actionMenuTextColor的顏色。將此行添加到您的主題中。

<item name="actionMenuTextColor">your color</item> 
相關問題