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...
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.
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>
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.
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.
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>
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);
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 :)
Related
My application's main theme inherits from Theme.AppCompat, and I've created a selector that allows for the Ripple effect to take place when you press and focus a button on Lollipop.
However, when I go back to a 4.0 device, it defaults back to an ugly blue color when I focus a list view item. I've looked everywhere for the trait that defines this color hoping to override it without any luck - any idea how I can do this?
Add this to your theme:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
...
<item name="android:listViewStyle">#style/ListViewAppTheme</item>
<item name="android:listViewWhiteStyle">#style/ListViewAppTheme.White</item>
</style>
<style name="ListViewAppTheme" parent="Base.Widget.AppCompat.ListView">
<item name="android:listSelector">#drawable/abc_list_selector_dark</item>
<item name="android:divider">#drawable/ab_divider_light</item>
<item name="android:dividerHeight">1px</item>
</style>
<style name="ListViewAppTheme.White" parent="Base.Widget.AppCompat.ListView.White">
<item name="android:listSelector">#drawable/abc_list_selector_dark</item>
<item name="android:divider">#drawable/ab_divider_light</item>
<item name="android:dividerHeight">1px</item>
</style>
Change #drawable/abc_list_selector_dark to whatever selector you want to use. As an added bonus, I added how to change the listview's divider and its height.
Unfortunately doesn't seem to be working. The list views still seem to
be getting that disgusting default blue color from SOMEWHERE, although
I can't figure out where.
I used to feel like you, both on the disgusting and the angry somewhere part. However I managed to get rid of it.
If I remember well, the culprit should be android:listChoiceBackgroundIndicator. Try this:
<style name="MainTheme" parent="Theme.AppCompat">
<item name="android:listChoiceBackgroundIndicator">#drawable/my_selector</item>
<item name="listChoiceBackgroundIndicator">#drawable/my_selector</item>
</style>
I have a spinner in a Holo theme dialog and am trying to change the text colour because it is very hard to read:
I have looked at android styles.xml, as well as many other answers, and believe that I am setting the custom style correctly; but it's just not getting picked up.
This is an extract from the dialog layout file where the spinner lives:
<Spinner
android:id="#+id/spn_Type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:entries="#array/dose_type_options"
style="#style/DialogSpinner" />
And these are the relevant entries in styles.xml in the values-v14 folder:
<style name="DialogSpinner" parent="#android:style/Widget.Holo.Spinner">
<item name="android:spinnerItemStyle">#style/MySpinnerItem</item>
</style>
<style name="MySpinnerItem" parent="android:Widget.Holo.TextView.SpinnerItem">
<item name="android:textAppearance">#style/MyTextAppearanceSpinnerItem</item>
</style>
<style name="MyTextAppearanceSpinnerItem" parent="android:TextAppearance.Holo.Widget.TextView.SpinnerItem">
<item name="android:textColor">#FFF</item>
</style>
The dialog itself is forced to the Holo dark theme by using:
<style name="FibroDialog" parent="#android:style/Theme.Holo.Dialog">
</style>
Can anyone identify why the spinner text isn't white?
I have looked at other solutions, which suggest changing the colour in code, but this app supports 2.3.* upwards, so for those non-holo versions black text is fine, hence trying to do it by styles.
Thanks
Updated using answer from Woda below
The text colour of the initial value of the spinner is now white, which goes a long way to highlighting that there is a spinner there for the user:
But the text colour of the selectable items is still black. I guess it's not a massive deal, at least the existence of the spinner has been affirmed by getting the initial text changed to white. But I would be interested to know why the items are still black, and how to change them to white.
Have you tried to accept the SpinnerItemStyle to your Theme? So all Spinners in your App would've the same style. I'm using it like this and it works:
theme.xml:
<style name="exampleTheme" parent="android:Theme.Holo.Light">
<item name="android:spinnerItemStyle">#style/SpinnerItem_example</item>
...
</style>
style.xml:
<style name="SpinnerItem_example" parent="android:TextAppearance.Widget.TextView.SpinnerItem">
<item name="android:textColor">#000000</item>
</style>
Update:
Taking a deeper look into the styles.xml brought me this:
<style name="Widget.DropDownItem.Spinner">
<item name="android:checkMark">?android:attr/listChoiceIndicatorSingle</item>
</style>
<style name="Widget.DropDownItem">
<item name="android:textAppearance">#style/TextAppearance.Widget.DropDownItem</item>
<item name="android:paddingStart">#dimen/dropdownitem_text_padding_left</item>
<item name="android:paddingEnd">#dimen/dropdownitem_text_padding_right</item>
<item name="android:gravity">center_vertical</item>
</style>
So you probably need to customize the Widget.DropDownItem and accept it in your theme.
...
<item name="dropDownItemStyle">#android:style/Widget.DropDownItem</item>
...
For customizing my application the following two links helped me a lot to understand the structure of the different views. These two files are part of the android source code. May be it helps you too.
themes.xml
styles.xml
I fixed it by calling
mArrayAdapter.setDropDownViewTheme(mActivity.getTheme());
Hope this helps someone ;)
You can access the internal TextView in code without changing any styles. This is how I handled enabling and disabling Spinners
The .getSelectedView() did not work for me. So I tricked the Spinner to "show" being disabled.
You will need to define your own colors for the "disabled" look.
For Example:
R.color.blue_text //means enabled
R.color.gray_text //means disabled
So to disable my spinner:
((TextView)mySpinner.getChildAt(0)).setTextColor(getResources().getColor(R.color.gray_text));
mySpinner.setEnabled(false);
mySpinner.setFocusable(false);
To enable my spinner:
((TextView)mySpinner.getChildAt(0)).setTextColor(getResources().getColor(R.color.blue_text));
mySpinner.setEnabled(true);
mySpinner.setFocusable(true);
The getChildAt(0) function allows you to access the first item in the spinner, which is what you show on the screen as a TextView.
You don't need to change styles or modify any XML. Just do this in your code, even within event methods, you should be fine.
I have a small question about theming my app that uses ActionBarSherlock. Everything works fine except on Samsung phones with TouchWizz. The overflow menu items appear by pressing the hardware menu key.
I know how to change the panel background. My default theme extends Theme.Sherlock.Light.DarkActionBar, so the default menu item text color in the hardware panel will be black, I wan't to change this.
Any ideas on how to do this besides changing the parent of my default theme?
<style name="Theme.MyApp" parent="#style/Theme.Sherlock.Light.DarkActionBar">
<item name="android:panelBackground">#drawable/menu_hardkey_panel</item>
</style>
I'm not sure if I understand what you want to do, but if you want to change textColor in this panel you can create custom style with parent set to TextAppearance.Sherlock.Widget.PopupMenu and then change textColor property. Like this:
<style name="Widget.MyApp.ActionBarPopupLargeTextColor" parent="TextAppearance.Sherlock.Widget.PopupMenu.Large">
<item name="android:textColor">#color/black</item>
</style>
<style name="Widget.MyApp.ActionBarPopupSmallTextColor" parent="TextAppearance.Sherlock.Widget.PopupMenu.Small">
<item name="android:textColor">#color/black</item>
</style>
Worked for me :)
Here are the correct attrs to tune hardware menu style.
You should look at panelColorForeground ;-)
<item name="android:panelColorBackground">#FFFFFF</item>
<item name="android:panelColorForeground">#color/primary_text_holo_dark</item>
<item name="android:panelFullBackground">#drawable/menu_background_fill_parent_width_holo_dark</item>
<item name="android:panelTextAppearance">#style/Holo.TextAppearance</item>
Tested on HoloEverywhere lib and 2.3 emulator.
See attrs doc for details.
I am the using the ActionBarSherlock. I have the displayOption "homeAsUp" in my style.xml file. Now this shows a black arrow next to the title of the Activity. Since my theme is White on a blue blackground, i want to change the color of the black arrow, or maybe use a whole new icon resource in its place. How can i do this ?
Kind Regards.
Further to Eric's answer - I wasted a lot of time getting this right.
Remember that these items must go in the parent application theme, inheriting from Theme.Sherlock or similar.
<!-- CUSTOM APP THEME -->
<style name="AppTheme" parent="Theme.Sherlock">
<item name="android:actionBarStyle">#style/AppTheme.ActionBarStyle</item>
<item name="actionBarStyle">#style/AppTheme.ActionBarStyle</item>
<item name="android:homeAsUpIndicator">#drawable/action_bar_ic_ab_back_holo_dark</item>
<item name="homeAsUpIndicator">#drawable/action_bar_ic_ab_back_holo_dark</item>
</style>
Do not put them in the custom Action Bar theme inheriting from Widget.Sherlock.ActionBar.
<!-- ACTION BAR THEME -->
<style name="AppTheme.ActionBarStyle" parent="Widget.Sherlock.ActionBar">
<item name="android:icon">#drawable/action_bar_logo</item>
<item name="icon">#drawable/action_bar_logo</item>
<item name="android:displayOptions">showHome</item>
<item name="displayOptions">showHome</item>
</style>
Be careful when you style ActionBarSherlock !
Here is an extract from the web site (ActionBarSherlock Theming):
Due to limitations in Android's theming system any theme customizations must be declared in two attributes. The normal android-prefixed attributes apply the theme to the native action bar and the unprefixed attributes are for the custom implementation. Since both theming APIs are exactly the same you need only reference your customizations twice rather than having to implement them twice.
So in your case you MUST define two item:
<item name="android:homeAsUpIndicator">#drawable/icon</item>
and
<item name="homeAsUpIndicator">#drawable/icon</item>
Then you are sure that ALL your users will have the same L&F
Ok, this is driving me bonkers. To skin my app, I set the following in my theme:
<item name="android:textColor">#FFFFFF</item>
All the text in the app turns white, unless I manually override it in the layout xmls. Great, yay, easy peasy. EXCEPT that the text in my menu options for context menus (off of lists and such) have also decided to become white.
This is not so great, since it is hard to read white on white. I have tried a variety of solutions, including searching for how to change the text color of a context menu (no dice)and creating a textAppearance item in my theme. The last solution didn't change all the textfields in my app, which was frustrating.
So, any suggestions? Hopefully my dilema is clear.
In your styles.xml try overriding the textViewStyle instead of just ALL textColor attributes:
<style name="Theme.Blundell.Light" parent="#android:style/Theme.NoTitleBar">
<item name="android:windowBackground">#drawable/background_light</item>
<item name="android:textViewStyle">#style/Widget.TextView.Black</item>
</style>
<style name="Widget.TextView.Black" parent="#android:style/Widget.TextView">
<item name="android:textColor">#000000</item>
</style>
You could even take it one further and just override the color for a certain view, like buttons:
<style name="Widget.Holo.Button" parent="#android:style/Widget.Holo.Button">
<item name="android:textColor">#FFFFFF</item>
</style>
<style name="Theme.Blundell" parent="#android:style/Theme.Holo.NoActionBar">
<item name="android:colorBackground">#android:color/transparent</item>
<item name="android:buttonStyle">#style/Widget.Holo.Button</item>
</style>
If your inspired to do any more theming check out the Android source it's the best place to realise what you can and can't do!:
https://github.com/android/platform_frameworks_base/tree/master/core/res/res/values
Use this:
parent="Theme.AppCompat.Light.DarkActionBar"