Change color buttons of the AppBar on Android

5

How to change the color of the buttons of the AppBar ?, in my case of the return button, the default color is white

But mine turns black and I want to change it to white try it with the accent colors and even then it does not change me.

    
asked by Gunnar 29.03.2016 в 00:18
source

3 answers

5

Do it programmatically:

final Drawable upArrow = getResources().getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
upArrow.setColorFilter(Color.parseColor("#FFFFFF"), PorterDuff.Mode.SRC_ATOP);
getSupportActionBar().setHomeAsUpIndicator(upArrow);

As of API 23 it went from abc_ic_ab_back_mtrl_am_alpha to abc_ic_ab_back_material

    
answered by 29.03.2016 / 00:33
source
2

With the following function you can apply to any icon of AppBar

public static void tintMenuItemIcon(Context context, Menu menu, int idItem, int color) {
    Drawable drawable = menu.findItem(idItem).getIcon();

    drawable = DrawableCompat.wrap(drawable);
    DrawableCompat.setTint(drawable,color ); 
    menu.findItem(idItem).setIcon(drawable);
}

Use:

It is recommended to change the color of menu items within AppBar in onCreateOptionsMenu

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.menu_routes, menu);

    GeneralUtils.tintMenuItemIcon(getActivity(), menu, R.id.action_sort, Color.WHITE);
    GeneralUtils.tintMenuItemIcon(getActivity(), menu, R.id.action_filter, Color.WHITE);

    super.onCreateOptionsMenu(menu, inflater);
}
    
answered by 15.10.2016 в 19:46
1

A solution without java code is to modify the stylo xml.

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

If you have it in Light, the button on the back colors it black, but with DarkActionBar it colors it white

    
answered by 25.07.2017 в 03:52