2016-11-16 48 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

這不是我的問題 –