ActionBarSherlock icon indicating copy to clipboard operation
ActionBarSherlock copied to clipboard

Text font color in dropdown items is still wrong in Light.DarkActionBar

Open jmgrosen opened this issue 14 years ago • 21 comments

I'm using Theme.Sherlock.Light.DarkActionBar in my project, along with a spinner in my Action Bar with elements of R.layout.sherlock_spinner_item. However, the text color is still the normal Holo Dark black. This is like #223, but it only applies to Light.DarkActionBar.

(Also, could you add a sherlock_spinner_dropdown_item? It would be much appreciated.)

jmgrosen avatar Feb 15 '12 05:02 jmgrosen

This is sort of a platform bug, actually. I noticed before the RC but chose to hold off on fixing it.

Basically what happens is the layout pulls the primary text color from the theme to use in the selected spinner view. On a dark theme the primary color is light and on a light theme the primary color is dark. As you said, the problem arises when you use light/dark because the theme is based on the light theme making the primary text color dark. Since the action bar is explicitly set dark, though, we get the black text on dark gray background.

The solution here is to provide your own spinner layout for the selected item which forces the use of a text appearance with a light text color. Since I imagine a lot of people will be having similar problems, I'll provide a sherlock_spinner_item_light_dark or something to save people the trouble.

Why did you want the sherlock_spinner_dropdown_item? I thought the built-in one worked fine on all the platforms I tested.

JakeWharton avatar Feb 15 '12 12:02 JakeWharton

The dark spinner item would be nice, thanks. At least for me, the built-in dropdown spinner item has the same color problem as the built-in spinner item. I could create my own, but I'm too lazy ;)

jmgrosen avatar Feb 15 '12 17:02 jmgrosen

http://code.google.com/p/android/issues/detail?id=25624

JakeWharton avatar Feb 16 '12 18:02 JakeWharton

You can remove your fix for that. This isn't a bug, it's using the wrong context. Using getSupportActionBar().getThemedContext() when creating the adapter solves it for me (tested on ics, gingebread and froyo).

gabrielittner avatar Mar 05 '12 10:03 gabrielittner

Great catch! I always forget about the themed context.

JakeWharton avatar Mar 05 '12 17:03 JakeWharton

Just tested it for the normal Holo.Light theme. You can also remove sherlock_spinner_dropdown_item and sherlock_spinner_item (commit was b744d1f/issue 223). Using the simple_spinner_item together with the themed context works fine.

This was the code I used: ArrayAdapter spinnerAdapter = ArrayAdapter.createFromResource(actionBar.getThemedContext(), R.array.app_navigation, android.R.layout.simple_spinner_item); spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

gabrielittner avatar Mar 05 '12 17:03 gabrielittner

On 2.3.4 it shows up incorrectly on pre-3.0 using the native layouts.

JakeWharton avatar Mar 06 '12 03:03 JakeWharton

Shit, shit, shit...getSupportActionBar().getThemedContext() doesn't work for me.. :( Ahhh what can I do? I searched the whole day for the solution and my app is already online. I'm getting the first negative reviews from people who had this bug.

public class DetailSearchActivity extends SherlockFragmentActivity { [...] public void onCreate(Bundle savedInstanceState) { [...] adapter_level = new BaseDataAdapter(getSupportActionBar().getThemedContext(), android.R.layout.simple_spinner_item, levelLst);

http://tinyurl.com/98kd57n <- here is the actual spinner style on android 2.2

I did not customisations - i'm just using the "Theme.Sherlock" theme..

fliese avatar Oct 08 '12 20:10 fliese

Use R.layout.sherlock_spinner_item.

JakeWharton avatar Oct 08 '12 22:10 JakeWharton

It won't work :(

fliese avatar Oct 08 '12 22:10 fliese

It will.

JakeWharton avatar Oct 08 '12 22:10 JakeWharton

Is this really fixed?

I am simply creating menu items (on the onPrepareOptionsMenu) and I can't change the style of the dropdown items with anything. I've tried like 10 different styling solutions but the menu shown is always with dark background and the app's default text color (which is dark grey and screws everything up).

This sample seems to be when you're creating a navigation spinner and not a menu spinner (the automatically generated when there's no space).

If this is not the same issue, could someone please point me in the right direction? Thanks

Draiken avatar Mar 05 '13 20:03 Draiken

@Draiken, have you found a solution? I am stuck with the very same problem. Thanks!

fbernhard avatar Mar 26 '13 01:03 fbernhard

@fbernhard yes, I have finally found it.

The style I successfully used is android:itemTextAppearance. I linked to a style that changed the textColor and voila!

Draiken avatar Mar 26 '13 02:03 Draiken

@Draiken perfect, thanks a lot, this works nicely!

fbernhard avatar Mar 26 '13 04:03 fbernhard

@Draiken I have just realized that this also changes the text color in the "long press context menu". I.e. your solutions solves the navigation spinner problem (it is now white font on dark background) but creates a new one for context menues (white font on white background). ;-(

fbernhard avatar Mar 28 '13 01:03 fbernhard

@fbernhard Hmm, I wondered if that changed something else too (name is pretty generic), but I only managed to fix that color with this style, fortunately for me I'm not affected by context menus.

You can probably change the background in the context menus, but it's not always a viable solution.

Draiken avatar Mar 28 '13 11:03 Draiken

I just want to chime in on this thread and say that the only thing that worked for me in the end (testing between 2.3.7 and 4.2.2) was using getSupportActionBarContext() instead of getSupportActionBar().getThemedContext().

Example: actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); ArrayAdapter list = ArrayAdapter.createFromResource(this.getSupportActionBarContext(), R.array.MainActivityTabs, R.layout.sherlock_spinner_item); list.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item); actionBar.setListNavigationCallbacks(list, this);

jschleppy avatar Apr 30 '13 23:04 jschleppy

I'm experiencing this issue when extendind the Light.DarkActionBar theme, running in API 9. Both background and text dark.

rafaeltoledo avatar May 09 '13 15:05 rafaeltoledo

rafeltoledo, not much anyone is going to be able to help you with when you don't post any code you've tried. Which context are you using? Though, I also wouldn't know from personal experience at all since our lowest supported api on all our apps is 10. You'd only be getting an additional 0.1% of the market by supporting api 9: http://developer.android.com/about/dashboards/index.html

Is it worth it for your app?

Though, I completely understand if dropping support of api 9 isn't an option for you, sometimes it just isn't. You may have to do something specific for that api only even. Best of luck.

jschleppy avatar May 09 '13 17:05 jschleppy