我已经将我的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。


当前回答

我们遇到了同样的问题我们想要的就是

应用:折叠图标

属性,我们没有找到,因为它不是很好的文档:)

<android.support.v7.widget.Toolbar
         android:id="@+id/toolbar"
         android:layout_width="match_parent"
         android:layout_height="@dimen/toolbarHeight"
         app:collapseIcon="@drawable/collapseBackIcon" />

其他回答

private fun setToolbarNavigationIconColor(context: Context, toolbar: Toolbar?, color: Int) {
    val drawableBack = toolbar?.navigationIcon
    drawableBack?.let {
        val drawableWrap = DrawableCompat.wrap(drawableBack).mutate()
        DrawableCompat.setTint(
            drawableWrap, ContextCompat.getColor(context, white)
        )
        toolbar.navigationIcon = drawableWrap
    }
}

只需添加

<item name="colorControlNormal">@color/white</item> 

到您当前的应用程序主题。

我们遇到了同样的问题我们想要的就是

应用:折叠图标

属性,我们没有找到,因为它不是很好的文档:)

<android.support.v7.widget.Toolbar
         android:id="@+id/toolbar"
         android:layout_width="match_parent"
         android:layout_height="@dimen/toolbarHeight"
         app:collapseIcon="@drawable/collapseBackIcon" />

查看工具栏和TintManager源代码,drawable/abc_ic_ab_back_mtrl_am_alpha是用样式属性colorControlNormal的值着色的。

我确实尝试在我的项目中设置这个(与<item name="colorControlNormal">@color/my_awesome_color</item>在我的主题),但它仍然是黑色的。

更新:

找到了。你需要用colorControlNormal设置actionBarTheme属性(不是actionBarStyle)。

Eg:

<style name="MyTheme" parent="Theme.AppCompat.Light">        
    <item name="actionBarTheme">@style/MyApp.ActionBarTheme</item>
    <item name="actionBarStyle">@style/MyApp.ActionBar</item>
    <!-- color for widget theming, eg EditText. Doesn't effect ActionBar. -->
    <item name="colorControlNormal">@color/my_awesome_color</item>
    <!-- The animated arrow style -->
    <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
</style>

<style name="MyApp.ActionBarTheme" parent="@style/ThemeOverlay.AppCompat.ActionBar">       
    <!-- THIS is where you can color the arrow! -->
    <item name="colorControlNormal">@color/my_awesome_color</item>
</style>

<style name="MyApp.ActionBarStyle" parent="@style/Widget.AppCompat.Light.ActionBar">
    <item name="elevation">0dp</item>      
    <!-- style for actionBar title -->  
    <item name="titleTextStyle">@style/ActionBarTitleText</item>
    <!-- style for actionBar subtitle -->  
    <item name="subtitleTextStyle">@style/ActionBarSubtitleText</item>

    <!-- 
    the actionBarTheme doesn't use the colorControlNormal attribute
    <item name="colorControlNormal">@color/my_awesome_color</item>
     -->
</style>

如果使用工具栏,你可以试试这个

Drawable drawable = toolbar.getNavigationIcon();
drawable.setColorFilter(ContextCompat.getColor(appCompatActivity, colorId), PorterDuff.Mode.SRC_ATOP);