我已将我的 SDK 更新到 API 21,现在备份/后退图标是一个指向左侧的黑色箭头。
我希望它是灰色的。我该怎么做?
例如,在 Play 商店中,箭头是白色的。
我这样做是为了设置一些样式。我已将 @drawable/abc_ic_ab_back_mtrl_am_alpha
用于 homeAsUpIndicator
。该drawable是透明的(只有alpha),但箭头显示为黑色。我想知道我是否可以像在 DrawerArrowStyle
中那样设置颜色。或者,如果唯一的解决方案是创建我的 @drawable/grey_arrow
并将其用于 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>
到目前为止,我的解决方案是使用看起来是白色的 @drawable/abc_ic_ab_back_mtrl_am_alpha
,并使用照片编辑器将其绘制成我想要的颜色。它可以工作,虽然我更喜欢像在 DrawerArrowStyle
中那样使用 @color/actionbar_text
。
最佳答案
你可以通过代码来实现。获取返回箭头drawable,通过滤镜修改颜色,设置为返回按钮。
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);
修订版 1:
从 API 23 (Marshmallow) 开始,可绘制资源 abc_ic_ab_back_mtrl_am_alpha
更改为 abc_ic_ab_back_material
。
编辑:
您可以使用此代码来实现您想要的结果:
toolbar.getNavigationIcon().setColorFilter(getResources().getColor(R.color.blue_gray_15), PorterDuff.Mode.SRC_ATOP);
关于java - 如何更改新 Material 主题中后退箭头的颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26788464/