Search code examples
androidandroid-actionbarandroid-toolbarandroid-actionbar-compat

Android toolbar overflow menu change text color and fill menu to the screen


there

I facing problem to change the text colour of toolbar/action bar overflow menu item. I do too many googling and reading Stackoverflow answers but it can not solve my prblem

enter image description here

currenlt i am getting black colour into overflow menu item.

what i want is 1. I want to change the colour of menu item black to WHITE. 2. I want to change the width of the overflow menu to match parent screen

my code:

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="AppTheme.Base">
    <!-- Customize your theme here. -->
</style>

<style name="AppTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimary">@color/primary</item>
    <item name="colorPrimaryDark">@color/primary_dark</item>
    <item name="colorAccent">@color/accent</item>
    <item name="android:textColorPrimary">@color/primary_text</item>
    <item name="android:textColorSecondary">@color/secondary_text</item>
    <item name="android:divider">@color/divider</item>
    <item name="icon">@color/icons</item>
    <item name="actionOverflowMenuStyle">@style/AppTheme.Base.PopupMenu</item>
</style>

<style name="AppTheme.Base.PopupMenu" parent="android:Widget.Holo.Light.ListPopupWindow">
    <item name="android:popupBackground">@color/primary</item>
</style>

Please, help me to solve this..

thanks in advance


Solution

  • finally i got the code for the convert black colour to white

    public boolean onPrepareOptionsMenu(Menu menu) {
        //return super.onPrepareOptionsMenu(menu);
        try {
            for (int i = 0; i < menu.size(); i++) {
                MenuItem mi = menu.getItem(i);
                mi.setIcon(R.drawable.ic_action_new);
                String title = mi.getTitle().toString();
                Spannable spannable = new SpannableString(title);
                spannable.setSpan(new ForegroundColorSpan(Color.WHITE), 0, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                mi.setTitle(spannable);
            }
        } catch (Exception ex) {
    
        }
        return true;
    }