如何改变后退箭头的颜色,在新材料的主题? [英] How to change color of the back arrow in the new material theme?
问题描述
我已经更新了我的SDK API 21现在返回/向上图标是一个黑色箭头指向左侧。
I've updated my SDK to API 21 and now the back/up icon is a black arrow pointing to the left.
我想它是灰色的。我该怎么办呢?
I would like it to be grey. How can I do that?
在Play商店,例如,箭头是白
In the Play Store, for example, the arrow is white.
我做这个设置一些样式。我已经使用 @绘制/ abc_ic_ab_back_mtrl_am_alpha
为 homeAsUpIndicator
。这可绘制是透明的(只有阿尔法),但箭头显示为黑色。我不知道我是否可以设置颜色像我这样的 DrawerArrowStyle
。或者,如果唯一的解决办法就是创建我的 @绘制/ grey_arrow
,并将其用于 homeAsUpIndicator
。
I've done this to set some styles. I have used @drawable/abc_ic_ab_back_mtrl_am_alpha
for homeAsUpIndicator
. That drawable is transparent (only alpha) but the arrow is displayed in black. I wonder if I can set the color like I do in the DrawerArrowStyle
. Or if the only solution is to create my @drawable/grey_arrow
and use it for homeAsUpIndicator
.
<!-- Base application theme -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:actionBarStyle" tools:ignore="NewApi">@style/MyActionBar</item>
<item name="actionBarStyle">@style/MyActionBar</item>
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
<item name="homeAsUpIndicator">@drawable/abc_ic_ab_back_mtrl_am_alpha</item>
<item name="android:homeAsUpIndicator" tools:ignore="NewApi">@drawable/abc_ic_ab_back_mtrl_am_alpha</item>
</style>
<!-- ActionBar style -->
<style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid">
<item name="android:background">@color/actionbar_background</item>
<!-- Support library compatibility -->
<item name="background">@color/actionbar_background</item>
</style>
<!-- Style for the navigation drawer icon -->
<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">@color/actionbar_text</item>
</style>
我的解决方案迄今已采取 @绘制/ abc_ic_ab_back_mtrl_am_alpha
,这似乎是白色的,写生,在我的愿望使用照片编辑器的颜色。它的工作原理,但我会preFER使用 @色/ actionbar_text
像 DrawerArrowStyle
。
My solution so far has been to take the @drawable/abc_ic_ab_back_mtrl_am_alpha
, which seems to be white, and paint it in the color I desire using a photo editor. It works, although I would prefer to use @color/actionbar_text
like in DrawerArrowStyle
.
推荐答案
您可以通过code ++实现的。获取后退箭头绘制,修改它的颜色过滤器,并将其设置为后退按钮。
You can achieve it through code. Obtain the back arrow drawable, modify its color with a filter, and set it as back button.
final Drawable upArrow = getResources().getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
upArrow.setColorFilter(getResources().getColor(R.color.grey), PorterDuff.Mode.SRC_ATOP);
getSupportActionBar().setHomeAsUpIndicator(upArrow);
这篇关于如何改变后退箭头的颜色,在新材料的主题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!