2017-04-21 91 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; 
}