我已经将我的SDK更新到API 21,现在备份/向上图标是一个指向左边的黑色箭头。
我希望它是灰色的。我该怎么做呢?
例如,在Play Store中,箭头是白色的。
我这样做是为了设置一些样式。我已经使用@drawable/abc_ic_ab_back_mtrl_am_alpha作为homeAsUpIndicator。该可绘制对象是透明的(只有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,它看起来是白色的,并使用照片编辑器将其涂成我想要的颜色。它的工作,虽然我更喜欢使用@color/actionbar_text像在DrawerArrowStyle。
最简单(也是最好)的方法来改变背面/向上箭头的颜色。最棒的是
没有副作用(不像其他答案)!
用父控件Widget.AppCompat创建一个样式。DrawerArrowToggle,定义颜色和其他你想要的属性。
在app Theme的drawerArrowStyle属性上设置样式。
创建样式:
<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
<!-- Set that the nav buttons will animate-->
<item name="spinBars">true</item>
<!-- Set the color of the up arrow / hamburger button-->
<item name="color">@color/white</item>
</style>
在App Theme中设置样式:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<!-- Change global up-arrow color with no side-effects -->
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
</style>
要更改工具栏的文本颜色(和其他属性),请创建以下样式:
<style name="ToolbarStyle" parent="Widget.AppCompat.Toolbar">
<item name="android:textColor">@color/white</item>
<item name="titleTextColor">@color/white</item>
<item name="colorControlNormal">@color/white</item> <!-- colorControlNormal is Probably not necessary -->
</style>
然后在AppTheme上设置该样式:
<!-- Base application theme. -->
<style name="AppTheme.MyProduceApp" parent="Theme.MaterialComponents.Light.NoActionBar.Bridge">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<!-- Style the toolbar (mostly the color of the text) -->
<item name="toolbarStyle">@style/ToolbarStyle</item>
<!-- Change color of up-arrow -->
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
</style>