2016-11-16 47 views
1

我设置操作栏中的后退箭头,并改变它的颜色像这样的颜色:更改默认后退箭头的通过动作条提供

final Drawable upArrow = getResources().getDrawable(R.drawable.ic_action_navigation_arrow_back); 
upArrow.setColorFilter(getResources().getColor(R.color.white), PorterDuff.Mode.SRC_ATOP); 
getSupportActionBar().setHomeAsUpIndicator(upArrow); 

正如你所看到的,我改变颜色在这条线的箭头,因为默认返回箭头是灰色的,在这里:

upArrow.setColorFilter(getResources().getColor(R.color.white), PorterDuff.Mode.SRC_ATOP); 

而且颜色变化,但它是一个有点透明虽然颜色white,我提供具有以下的十六进制代码的问题#FFFFFFFF

这里有两张图片可以让我的观点变得清晰。

这是它的外观:

This is how it looks

虽然颜色应该喜欢这样的其他组件:

enter image description here

我试着PorterDuff.Mode.XXXX下所有的选项,但没有工作。

+0

**看看这个** [已经拥有答案](http://stackoverflow.com/questions/31870132/how-to-change-color-汉堡包图标在材料设计导航抽屉) – Abhishek

+0

@Abhishek不,这是不是同一个问题,因为我不问如何改变项目的颜色,而是问为什么颜色过滤不给所需结果 –

回答

1

如果您使用工具栏,然后 添加项目在您的AppTheme。

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

但请确保您的布局的工具栏元素中没有定义其他主题。在style.xml

+0

我正在使用自定义工具栏 –

+0

谢谢。工作很好 –

2

PLZ变化

<style name="MyCustomTheme" parent="Custom.Base"> 

    </style> 

<style name="Custom.Base" parent="Theme.AppCompat.Light.DarkActionBar"> 
    <item name="windowNoTitle">true</item> 
    <item name="windowActionBar">false</item> 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorAccent</item> 
    <item name="drawerArrowStyle">@style/DrawerArrowStyle</item> 
</style> 

<style name="DrawerArrowStyle" parent="@style/Widget.AppCompat.DrawerArrowToggle"> 
    <item name="spinBars">true</item> 
    <item name="color">@android:color/white</item> 
</style> 
+0

这不是我的问题 –