2017-04-21 90 views
8

我在我的Android應用程序中有一個android.support.v7.widget工具欄。它的背景顏色是鮮豔的橙色,最上面的顏色是白色而不是黑色。更改工具欄溢出圖標顏色

我有黑色的默認顏色,而不是白色。由於它會與其他東西衝突,這幾乎不可能覆蓋。 我無法將主要文字顏色更改爲白色!

我已經設法改變標題顏色。 我現在要找的是我如何改變動作按鈕顏色(以白色)。

enter image description here

感謝

編輯:包括代碼現在

主要活動:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
tools:context=".UI.activities.MainActivity"> 

<android.support.v7.widget.Toolbar 
    android:id="@+id/r2_toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="?attr/actionBarSize" 
    android:background="?attr/colorPrimary" 
    android:elevation="4dp" 
    app:titleTextColor="@color/primary_text_material_light" 
    app:subtitleTextColor="@color/primary_text_material_light" 
    android:theme="@style/R2Theme.Toolbar"/> 

<fragment android:name="com.r2retail.r2retailapp.UI.fragments.SetupFragment" 
    android:layout_below="@+id/r2_toolbar" 
    android:id="@+id/list" 
    android:layout_weight="1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 


</RelativeLayout> 

菜單欄:

<?xml version="1.0" encoding="utf-8"?> 
<menu xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto"> 

<item android:id="@+id/about" 
    android:icon="@drawable/ic_menu" 
    android:title="About" 
    app:showAsAction="never"/> 

</menu> 

款式:

<resources> 

<style name="R2Theme" parent="Theme.AppCompat.Light.NoActionBar">= 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorPrimary</item> 
    <item name="android:textColorPrimary">@color/secondary_text_material_dark</item> 
    <item name="android:textColorSecondaryInverse">@color/primary_text_material_light</item> 
</style> 

<style name="R2Theme.Toolbar" parent="R2Theme"> 
    <item name="actionMenuTextColor">@color/primary_text_material_light</item> 
</style> 

</resources> 
+0

顯示你的代碼的東西,包括與該按鈕工具欄。 –

+0

@SatanPandeya我添加了代碼 –

+0

是否沒有辦法自定義ic_menu顏色,直接從它的文件中改變'fillColor'? –

回答

17

在款式:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
    ... 
    <item name="actionOverflowButtonStyle">@style/MyOverflowButtonStyle</item> 
</style> 

<style name="MyOverflowButtonStyle" parent="Widget.AppCompat.ActionButton.Overflow"> 
    <item name="android:tint">#62ff00</item> 
</style> 

結果:

enter image description here

+2

最後,一些簡單!在幾秒鐘內完成工作,沒有一個困難。完美解決方案謝謝! –

1

解決方案是替換圖標本身。

轉到valuse /風格並在styles.xml文件中加入:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
     <!-- Customize your theme here. --> 
     <item name="android:actionOverflowButtonStyle">@style/MyActionButtonOverflow</item> 
</style> 

<style name="MyActionButtonOverflow" parent="android:style/Widget.Holo.Light.ActionButton.Overflow"> 
    <!--Here you need to put name of drawable you will create during the next step--> 
    <item name="android:src">@drawable/your_white_icon</item> 
</style> 

第二

然後前往繪製文件夾。用鼠標右鍵單擊 - >新建 - >矢量資產。 然後按圖標圖像,並從建議的圖標中選擇名爲ic_more_vert_black_24dp

自定義它 - >按下一步 - >完成。

然後打開新創建的圖標文件。代碼看起來像這樣。

<vector xmlns:android="http://schemas.android.com/apk/res/android" 
     android:width="24dp" 
     android:height="24dp" 
     android:viewportWidth="24.0" 
     android:viewportHeight="24.0"> 
    <path 
     android:fillColor="#FFFFFFFF" <!-- Here u can change color--> 
     android:pathData="M12,8c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2 -2,0.9 -2,2 0.9,2 2,2zM12,10c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2zM12,16c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2z"/> 
</vector> 

更改fillColor屬性爲您需要的顏色。把這個文件放在第一步描述的樣式中。

瞧!我們的三點顏色的顏色更改不取決於基本應用程序樣式(#FF2012顏色的結果)。

enter image description here

0

的另一種方式,在代碼而不是XML:

public static boolean colorizeToolbarOverflowButton(@NonNull Toolbar toolbar, @ColorInt int color) { 
    final Drawable overflowIcon = toolbar.getOverflowIcon(); 
    if (overflowIcon == null) 
     return false; 
    toolbar.setOverflowIcon(getTintedDrawable(toolbar.getContext(), overflowIcon, toolbarIconsColor)); 
    return true; 
} 

public static Drawable getTintedDrawable(@NonNull Context context, @NonNull Drawable inputDrawable, @ColorInt int color) { 
    Drawable wrapDrawable = DrawableCompat.wrap(inputDrawable); 
    DrawableCompat.setTint(wrapDrawable, color); 
    DrawableCompat.setTintMode(wrapDrawable, Mode.SRC_IN); 
    return wrapDrawable; 
} 

如果成功着色溢出圖標,該函數將返回true。

而另一種選擇,如果你不喜歡使用有色繪製:

public static boolean colorizeToolbarOverflowButton(@NonNull Toolbar toolbar, @ColorInt Integer color) { 
    final Drawable overflowIcon = toolbar.getOverflowIcon(); 
    if (overflowIcon == null) 
     return false; 
    final PorterDuffColorFilter colorFilter = toolbarIconsColor == null ? null : new PorterDuffColorFilter(toolbarIconsColor, PorterDuff.Mode.MULTIPLY); 
    overflowIcon.setColorFilter(colorFilter); 
    return true; 
}