如何在新材料主题中更改工具栏主页图标(后退箭头)颜色?

时间:2016-04-26 14:29:27

标签: android material-design toolbar android-appcompat android-tablayout

我在

这样的链接上逐个尝试了所有内容

How to change color of the back arrow in the new material theme?

How to change Toolbar home icon color

Change toolbar back arrow color

How to change change text and arrow color on Toolbar?

Android: unable to change color of back arrow navigation icon

但是没有什么对我有用。

我的布局xml代码,

<style name="MyCustomTabLayout" parent="Theme.AppCompat.Light">
    <item name="tabIndicatorHeight">2dp</item>
    <item name="tabPaddingStart">12dp</item>
    <item name="android:layout_width">match_parent</item>
    <item name="tabPaddingEnd">12dp</item>
    <item name="tabBackground">@drawable/background_tab_item</item>
    <item name="tabIndicatorColor">@color/jd_yellow</item>
    <item name="android:layout_gravity">center</item>
    <item name="android:gravity">center</item>
    <item name="tabSelectedTextColor">@color/jd_white</item>
    <item name="tabTextAppearance">@style/MyCustomTabTextAppearance</item>
    <item name="android:textAppearance">@style/MyCustomTabTextAppearance</item>
    <item name="android:background">@drawable/background_tab_item</item>
    <item name="android:textColorSecondary">@color/jd_white</item>
    <item name="colorControlNormal">@color/jd_white</item>
    <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
    <item name="actionBarTheme">@style/MyApp.ActionBarTheme</item>
    <item name="actionBarWidgetTheme">@style/WidgetStyle</item>
    <item name="colorPrimary">@color/jd_white</item>
    <item name="colorPrimaryDark">@color/jd_white</item>
    <item name="android:textColorPrimary">@color/jd_white</item>
</style>

<style name="WidgetStyle" parent="style/ThemeOverlay.AppCompat.Light">
    <item name="colorControlNormal">@color/jd_white</item>
</style>

<style name="MyApp.ActionBarTheme" parent="@style/ThemeOverlay.AppCompat.ActionBar">
    <!-- change color the arrow or three lines -->
    <item name="colorControlNormal">@color/jd_white</item>
</style>

<!-- Style for the navigation drawer icon -->
<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
    <item name="spinBars">true</item>
    <item name="color">@color/jd_white</item>
</style>

<style name="MyCustomTabTextAppearance" parent="TextAppearance.Design.Tab">
    <item name="android:textColor">@color/jd_white</item>
    <item name="android:textSize">@dimen/tab_layout_text_size</item>
    <item name="android:layout_width">match_parent</item>
    <item name="android:layout_height">match_parent</item>
    <item name="android:layout_gravity">center</item>
    <item name="android:gravity">center</item>
</style>
style.xml中的

  Drawable upArrow = ContextCompat.getDrawable(mContext, R.drawable.abc_ic_ab_back_material);
        upArrow.setColorFilter(ContextCompat.getColor(mContext, R.color.white), PorterDuff.Mode.SRC_ATOP);
        getSupportActionBar().setHomeAsUpIndicator(upArrow);

还尝试将以下内容添加到onCreate()

section .text
   global _start        

_start:                 

mov eax , 0         ;move value 0 to register eax
mov ebx , 1         ;move value 1 to register ebx
mov ecx , 1         ;move value 1 to register ecx
mov edx , 10        ;move value 10 to register edx

loop:               ;start of loop
mov ebx, ecx        ;move contents of ecx into ebx
add ebx, eax        ;add contents of eax into ebx
mov ecx, eax        ;move contents of eax into ecx
dec edx             ;decrement counter register edx
cmp edx, 0          ;compare counter edx to 0
jne loop            ;jump back into loop unless counter equals 0

没什么可行的,它的颜色仍然是黑色, 我做错了什么?请帮忙。

4 个答案:

答案 0 :(得分:2)

您可以用自己喜欢的任何颜色制作自己的资源,然后将其放在工具栏上。

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeAsUpIndicator(R.drawable.YOUR_ASSET);

答案 1 :(得分:0)

尝试将此样式用作工具栏的android:theme:

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    style="@style/MyCustomTabLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:background="?attr/colorPrimary"
    android:elevation="6dp"
    android:minHeight="?attr/actionBarSize"
    android:theme="@style/ToolbarStyle"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

'12.abd23yahoo 04/44 231'

答案 2 :(得分:0)

经过无数次黑客攻击和奇怪的怪异情况后,这就像魅力一样

 <style name="App"/>
<style name="App.Toolbar">
    <item name="android:id">@id/toolbar</item>
    <item name="android:layout_width">match_parent</item>
    <item name="android:layout_height">?attr/actionBarSize</item>
    <item name="android:background">@android:color/white</item>
    <item name="android:minHeight">?attr/actionBarSize</item>
    <item name="android:theme">@style/ThemeOverlay.AppCompat.Light</item>
    <item name="popupTheme">@style/ThemeOverlay.AppCompat.Dark</item>
</style>
<style name="App.Toolbar.Transparent">
    <item name="android:background">@android:color/transparent</item>
</style>

答案 3 :(得分:0)

很简单,这对我有用:

    <android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="56dp"
    android:background="@color/PrimaryColor"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    android:elevation="4dp" />