2015-02-24 36 views
5

Tôi đang sử dụng thanh công cụ android appcompat mới. Tôi cần phải đặt cùng một màu tùy chỉnh cho cả biểu tượng bánh mì kẹp thịt và các biểu tượng mũi tên quay lại. Sử dụng drawerArrowStyle cho phép tôi thay đổi biểu tượng burger nhưng không phải là mũi tên. Vấn đề là chỉ trên các thiết bị Lollipop, bất cứ điều gì trước kẹo que là tốt.Android: không thể thay đổi màu của biểu tượng điều hướng mũi tên quay lại

Burger

Arrow

Đây là mã:

Toolbar:

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

Tôi đã thử sử dụng giải pháp từ here nhưng nó không hoạt động. Bất cứ ai có bất kỳ ý tưởng?

+0

có thể trùng lặp của [Cách thay đổi màu của mũi tên quay lại trong chủ đề tài liệu mới?] (Http://stackoverflow.com/questions/26788464/how-to-change-color-of-the- back-arrow-in-the-new-material-theme) – Daniel

Trả lời

1

Đường dẫn đến các giải pháp phù hợp cho vấn đề tôi thấy here

Tuy nhiên điều này vẫn không 100% làm việc do chúng tôi sử dụng DrawerLayout. Đồng nghiệp của tôi đã viết một bài rất hay về các giải pháp here

+0

Kiểm tra câu trả lời của tôi hoạt động 100% – Daniel

+0

Liên kết tuyệt vời, tôi chỉ phải thay đổi Chủ đề để thiết lập đúng cách, nhưng điều này sẽ trả về điểm khi Ngăn kéo được sử dụng, nó có một hiệu ứng thú vị chống lại các drawables. – Silmarilos

2

Chỉ cần làm điều này trong hoạt động của bạn/Fragment:

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

Tôi cũng không thể cập nhật lại nút mũi tên sau khi nâng cấp lên thư viện 23.2.0 hỗ trợ

<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

Đó là màu hành độngMenuTextColor. Thêm dòng này vào chủ đề của bạn.

<item name="actionMenuTextColor">your color</item> 
Các vấn đề liên quan