4

I have a Toolbar, I want to change background to Black but by default items color is black and I want to change their color to gray, how can I do that ? Thanks you so much: My Image about Toolbar

And this is my toolbar.xml

<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#2196F3"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

My styles.xml

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>
RKRK
  • 1,284
  • 5
  • 14
  • 18
Jason Momoa
  • 123
  • 8

2 Answers2

1

While creating an icon or vector asset, you can select the color

enter image description here

Click on the color selector.

If you want to change color in code then add app:iconTint="@color/yourcolor" in your MenuItem for change the Icon color.

<item
android:icon="@drawable/ic_share_white_24dp"
android:id="@+id/action_share"
android:title="@string/action_share"
android:orderInCategory="200"
app:iconTint="@color/yourcolor"
app:showAsAction="ifRoom"
app:actionProviderClass="android.support.v7.widget.ShareActionProvider"/>

For changing the 3 dots icon color, try adding this in styles.xml

<style name="YourCustomTheme.OverFlow">
    <item name="android:src">@drawable/my_overflow_image</item>
</style>
Dev Sharma
  • 634
  • 7
  • 26
1

Change the tint attribute of the icon.

Via xml:

<item android:id="@+id/slash_toolbar" 
android:title="" 
android:icon="@drawable/ic_voice" 
app:showAsAction="always" 
android:tint="@android:color/white"/>

Via code:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_main, menu);

    for(int i = 0; i < menu.size(); i++){
        Drawable drawable = menu.getItem(i).getIcon();
        if(drawable != null) {
            drawable.mutate();
            drawable.setColorFilter(getResources().getColor(R.color.textColorPrimary), PorterDuff.Mode.SRC_ATOP);
        }
    }

    return true;
}

To change the three dots color put it in your style.xml in AppTheme:

<!-- android:textColorSecondary is the color of the menu overflow icon (three vertical dots) -->
<item name="android:textColorSecondary">@color/white</item>
Ricardo A.
  • 685
  • 2
  • 8
  • 35