21

The application I've been developing uses ActionBarSherlock, and the main theme inherits from Theme.Sherlock.Light.DarkActionBar. The design requires that the overflow menu popups have a dark coloured background and white text. This works fine for devices without a physical menu button, and the text appears white as intended. However, if the device DOES have a physical menu button, the text shown in the menu displayed remains black.

My main theme contains

<item name="android:panelBackground">@drawable/menu_hardkey_panel</item>

...Where @drawable/menu_hardkey_panel is a dark coloured 9patch.

The resulting appearance of the menu popup is... Light.DarkActionbar issue

I'm unable to determine why this is happening, or how to manually change the colour of the text. In my main theme, I've tried all of the following...

<item name="android:actionMenuTextColor">@android:color/white</item>
<item name="android:textAppearanceLargePopupMenu">@style/MyMenuTextAppearance.Large</item>
<item name="android:textAppearanceSmallPopupMenu">@style/MyMenuTextAppearance.Small</item>

I've even tried

<item name="android:actionBarWidgetTheme">@style/Theme.MyApp.Dark</item>

...Where Theme.MyApp.Dark is...

<style name="Theme.MyApp.Dark" parent="@style/Theme.Sherlock">
    <item name="android:dropDownListViewStyle">@style/DropDownListView</item>
    <item name="dropDownListViewStyle">@style/DropDownListView</item>
</style>

None have let me change the text to white. If I make my base theme inherit from Theme.Sherlock, the problem is solved and the text is white, but unfortunately that's not an option.

Chris Horner
  • 1,994
  • 2
  • 16
  • 26
  • 2
    have you tried both with and without `android`? eg: `@android:color/white` and `@android:color/white` ??? – ALiGOTec Nov 14 '12 at 12:32
  • Sure have. Alas, it does not solve the issue. – Chris Horner Nov 14 '12 at 22:18
  • I have an HTC Sensation with ICS and a menu button. I tested code from Commonsware at https://github.com/commonsguy/cw-omnibus/tree/master/EmPubLite/T7-ActionBar, which uses Theme.Sherlock.Light.DarkActionBar, but I don't have the problem you're describing. Maybe you want to try that code (it's a very small program) and see if you have the problem in that app, too, or indicate how it's different from yours. – hBrent Nov 17 '12 at 21:51
  • From my understanding, popup menus spawned with Light.DarkActionBar will have a light background and dark text. The theme of the app I'm developing requires the popup menus to have a dark background and light text. It also requires me to use Light.DarkActionBar as opposed to the regular Theme.Sherlock, as almost all other widgets within the app are "light" themed. – Chris Horner Nov 19 '12 at 01:12
  • Maybe try the support page for ActionBarSherlock: http://actionbarsherlock.com/support.html. There are links with different ways to get help, including contacting Jake Wharton directly. – hBrent Nov 20 '12 at 16:35
  • BTW, I searched the ActionBarSherlock Google group for Theme.Sherlock.Light.DarkActionBar, and it seems that other people are having this problem, but I didn't see a solution that worked for everyone. – hBrent Nov 20 '12 at 16:53
  • Is this on a post-Honeycomb device? – Jason Robinson Nov 20 '12 at 22:53
  • did you find the solution for this ? – Gal Ben-Haim Feb 20 '13 at 23:15
  • Sadly no. I resorted to using a white 9patch for the "android:panelBackground" to ensure the text was legible. – Chris Horner Feb 20 '13 at 23:56
  • My solution, check it out: http://stackoverflow.com/a/16812229/691993 – Oleksii Malovanyi May 29 '13 at 11:07

6 Answers6

2

Not entirely sure about this, but I believe the pop-up menu uses the same styling as the overflow menu. In which case you'd just do something like this.

<item name="android:itemTextAppearance">@style/your_new_text_appearance</item>

<style name="your_new_text_appearance">
    <item name="android:textColor">@android:color/white</item>
</style>
Ifrit
  • 6,791
  • 8
  • 50
  • 79
1

Giving it a chance: there is a text appearance called actionMenuTextAppearance. Have you tried that?

Update: I did some more digging and I believe that this file is the layout And there they refer to textAppearanceListItemSmall and textAppearanceSmall. However, it takes this value from a special theme which is specified as following in Theme.Holo.Light

<item name="panelMenuListTheme">@android:style/Theme.Holo.Light.CompactMenu</item>

And like this in Theme.Holo:

<item name="panelMenuListTheme">@android:style/Theme.Holo.CompactMenu</item>

The problems comes from the fact that the parent of Sherlock.__Theme.DarkActionBar is Theme.Sherlock.Light. This is not valid for the dark action bar. Taking the line from Theme.Holo should do the trick.

Tobias Ritzau
  • 3,327
  • 2
  • 18
  • 29
  • Are you sure it is a pop up? The vocabulary is really messed up. Can you post code that shows an example of this going wrong? – Tobias Ritzau Nov 20 '12 at 22:00
  • That's true, I'm not 100% sure that "pop up" is the correct technical term. I've edited the original question to outline precisely how to recreate the issue. – Chris Horner Nov 20 '12 at 22:23
  • This is tricky indeed... I may have found the layout file for the menu and the cause of the problem. I'm updating my answer. – Tobias Ritzau Nov 21 '12 at 06:41
  • I just tried adding @android:style/Theme.Holo.CompactMenu (and also android:panelMenuListTheme), but the compiler throws me the error: No resource found that matches the given name: attr 'panelMenuListTheme' Perhaps I'm misinterpreting your answer? – Chris Horner Nov 21 '12 at 07:55
  • I see now that it is an internal resource... And as far as I remember you can not access the internal attributes using the @*android: syntax... Hm, I'll go looking for a work around. – Tobias Ritzau Nov 21 '12 at 08:02
  • 1
    I have only found a half way workaround, but you should be able to make Sherlock.__Theme.DarkActionBar inherit from Theme.Sherlock (to get the panels right), and the reset all other attributes that are public from Theme.Holo.Light and Theme.Sherlock.Light. That is tedious but should get you close. – Tobias Ritzau Nov 21 '12 at 10:37
1

In my research I haven't found a way to change the text color, but you can at least handle hardkey menus gracefully.

This link provided me with a passable solution to the problem: https://github.com/jgilfelt/android-actionbarstylegenerator/issues/30

Commenting out the "android:panelBackground" item from my generated theme allowed the text to at least be visible on hardkey menus, even if it doesn't perfectly match the theme.

You could also try replacing the "menu_hardkey_panel_whatever.9.png" drawable with something that will work for your theme and the black text.

0

For me this solves the problem, try this instead:

<style name="MyTheme" parent="Theme.Sherlock.Light.DarkActionBar">
    ...
    <item name="actionBarWidgetTheme">@null</item>
    <item name="android:actionBarWidgetTheme">@null</item>
    ...
</style>
postNuKe
  • 341
  • 3
  • 8
0

I found the solution, use:

getSupportActionBarContext()

e.g.

ArrayAdapter<CharSequence> list =
            ArrayAdapter.createFromResource(getSupportActionBarContext(), R.array.navigation, layout.simple_spinner_item);
    list.setDropDownViewResource(layout.simple_spinner_dropdown_item);

    getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
    getSupportActionBar().setListNavigationCallbacks(list, this);
Michał Jurczuk
  • 3,728
  • 4
  • 32
  • 56
-1

I think that due to the fact that Theme.Sherlock.Light.DarkActionBar don't style its contents right is due to the actionWidgetTheme attribute is used with a ContextThemeWrapper for inflating the action bar views (Jake Wharton's own words), thus something like the following (not tested) will be needed to fulfill your needs, though breaking your need of not using Theme.Sherlock as parent in one way:

<style name="MyColorTheme" parent="Theme.Sherlock">
    <item name="android:actionMenuTextColor">@android:color/white</item>
    <item name="actionMenuTextColor">@android:color/white</item>
</style>

<style name="YourMainTheme" parent="Theme.Sherlock.Light.DarkActionBar">
    <item name="android:actionMenuTextAppearance">@style/MyColorTheme</item>
    <item name="actionMenuTextAppearance">@style/MyColorTheme</item>
</style>

Might work or not work. That's the question :)

Widerberg
  • 1,118
  • 1
  • 10
  • 24