Home » Android » android – Overflow Menu textColor with AppCompat (using Hardware Menu-Key)

android – Overflow Menu textColor with AppCompat (using Hardware Menu-Key)

Posted by: admin May 14, 2020 Leave a comment

Questions:

I’m facing an issue on devices with a separate menu key (like the Samsung onces).
In some Activities the textcolor of the Overflow Menu Items is white when opened via the Menu-Key. Opening the Overflow via the three dots the textcolor is always black – like it should be.

Following a Screenshot which visualizes the issue. On the left side the everything is fine, overflow has been opened via the three dots. On the right side the menu has been opened via the Menu-Key:

picture illustrating the issue

My Theme:

<style name="AppThemeToolbar" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/primary_color</item>
    <item name="colorPrimaryDark">@color/primary_color_dark</item>
    <item name="colorAccent">@color/accent_color</item>
    <item name="android:textColorPrimary">@android:color/white</item>
    <item name="android:textColorSecondary">@android:color/white</item>

    <item name="windowActionModeOverlay">true</item>
    <item name="actionModeBackground">@color/action_mode_color</item>
    <item name="actionBarPopupTheme">@style/ThemeOverlay.AppCompat.Light</item>
</style>

Note: I’m using the exact same Theme in multiple Activities though in 3 out of 5 everything is fine.
That’s totally mind boggling and doesn’t make sense.

So basically the question is: How can I fix this and why is the textcolor in some activities black and in others white (while they’re all using the same Theme)?


What I’ve tried (found in other similar posts):

  1. Setting the panelBackground. This works, unfortunately this isn’t a solution for me since the textcolor switches at will between black and white – so there’s simply no good background color I could set.
  2. What didn’t work:
    • android:panelTextAppearance
    • textAppearanceSmallPopupMenu
    • textAppearanceLargePopupMenu
    • popupMenuStyle
    • android:actionMenuTextColor & actionMenuTextColor
  3. I don’t wanna use SpannableStrings – approach seems to hacky
How to&Answers:

Finally found the solution!

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="actionBarPopupTheme">@style/HardwareOptionMenu</item>
</style>

<style name="HardwareOptionMenu" parent="ThemeOverlay.AppCompat.Dark">
    <item name="android:textColorSecondary">@color/white</item>
    <item name="android:colorBackground">@color/black</item>
</style>

Answer:

 <style name="AppThemeLL" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="android:windowActionBar">false</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:colorBackground">@color/white</item>
    <item name="android:textColorSecondary">@color/white</item>
</style>

This style worked for me and for the activity where you will use this theme extend Activity class.

Example:

public class TestActivity extends Activity
{}

Also your manifest will be

<activity android:name=".TestActivity"
        android:label="Test"
        android:theme="@style/AppThemeLL"/>

Answer:

I faced similar issue. You could try this for AppCompat :-

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="actionBarPopupTheme">@style/HardwareOptionMenu</item>
</style>

<style name="HardwareOptionMenu" parent="ThemeOverlay.AppCompat.Dark">
    <item name="android:textColorSecondary">@color/black</item>
    <item name="android:colorBackground">@color/white</item>
</style>