I implemented in my application the (not so) new Appcompat theme with DarkActionBar. Everything works fine, except the popup from hardware menu button (or long press the recent button), that is rendered with white text.
Popup result:
Toolbar: http://i.stack.imgur.com/huWpm.png
Hard menu: http://i.stack.imgur.com/o5fmL.png
I solved an old issue with the popup from Action Mode, adding the actionBarPopupTheme attribute in the app theme. After this, the Hardware Menu popup is also getting the background from actionBarPopupTheme (Ok, we want! Before it was black), but not the textcolor.
The code:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/primary</item>
<item name="colorPrimaryDark">#color/primary_dark</item>
<item name="windowActionModeOverlay">true</item>
<item name="actionBarTheme">#style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
<item name="actionBarPopupTheme">#style/ThemeOverlay.AppCompat.Light</item>
</style>
<style name="Toolbar" parent="MatchWidth">
<item name="theme">#style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
<item name="popupTheme">#style/ThemeOverlay.AppCompat.Light</item>
<item name="android:layout_height">?attr/actionBarSize</item>
<item name="android:background">?attr/colorPrimary</item>
</style>
What is the right way to theme this?
Related
In my Android app, I am using a popup menu but its background is green.
I want it to be white.
The background is white if I run it on my Android 6.0 device, but shows up green on my Jellybean device.
I'm not using the Actionbar.
There are many posts about this issue and I've tried probably most of them but can't find the solution.
The closest I got was a white background but then the border disappears.
Or I get a white background but when pressing on an item, the selection shows a grey background except for the text's background which shows white.
I'm using AppCompat.
Here are some of the things I've tried:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowActionBar">false</item>
<item name="colorControlActivated">#d06655</item>
<item name="colorAccent">#ffe6e2</item>
<item name="android:colorActivatedHighlight">#ffe6e2</item>
<item name="android:windowBackground">#color/white</item>
<!--<item name="android:popupMenuStyle">#style/PopupMenu</item>-->
<!--<item name="android:itemBackground">#color/white</item>-->
<item name="popupMenuStyle">#style/myPopupMenuStyle</item>
<item name="android:popupMenuStyle">#style/myPopupMenuStyle</item>
</style>
<!--<style name="PopupMenu" parent="Widget.AppCompat.PopupMenu">-->
<!--<style name="PopupMenu" parent="#style/Widget.AppCompat.PopupMenu">-->
<style name="myPopupMenuStyle" parent="#style/Widget.AppCompat.Light.PopupMenu">
<item name="android:popupBackground">#android:color/white</item>
</style>
You can brash the popup menu by using Android Action Bar Style Generator(or create a 9patch background by your own).
So all I did was - specify proper colour in the generator, get 9patched background(menu_dropdown_panel_background.9.png) back and set it as a background:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="popupMenuStyle">#style/PopupMenu.Example</item>
</style>
<style name="PopupMenu.Example" parent="#style/Widget.AppCompat.Light.PopupMenu">
<item name="android:popupBackground">#drawable/menu_dropdown_panel_background</item>
</style>
That's it!
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:
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):
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.
What didn't work:
android:panelTextAppearance
textAppearanceSmallPopupMenu
textAppearanceLargePopupMenu
popupMenuStyle
android:actionMenuTextColor & actionMenuTextColor
I don't wanna use SpannableStrings - approach seems to hacky
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>
<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"/>
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>
How do i fix this? The issue is simple, when the app is open the styling is fine. However, when i pull up the multitasking menu, the action bar does not retain its styling (mainly color) and appears the color of the parent theme.
You are using Lolipop maybe.
You can set color when you pull up the multitasking menu.
Add this in your app style (style.xml)
<item name="colorPrimary">yourColor</item>
<item name="colorAccent">AccentColor</item>
<item name="colorPrimaryDark">DarkColor</item>
Example :
<style name="AppTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/favorite_color</item>
<item name="colorAccent">#color/favorite_color</item>
<item name="colorPrimaryDark">#color/favorite_dark_color</item>
<item name="android:actionBarStyle">#style/Widget.ActionBar</item>
<item name="actionBarStyle">#style/Widget.ActionBar</item>
</style>
since last night I'm expecting this weird behavior of my application theme:
Popup menus appear with black background and AlertDialogs with white text color.
By the way, heres my styles.xml:
<resources xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android">
<style name="CustomActionBarTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle" tools:ignore="NewApi">#style/MyActionBar</item>
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar"
parent="Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#drawable/action_bar_background</item>
<!-- Support library compatibility -->
<item name="background">#drawable/action_bar_background</item>
</style>
</resources>
Any idea whats wrong? I just want the popup menu to use the default light theme again and the alert dialog to use a black foreground color.
Why do you think it is wrong?
PopupWindow background is dark in Theme.Light:
<style name="Widget.PopupWindow">
<item name="android:popupBackground">#android:drawable/editbox_dropdown_background_dark</item>
<item name="android:popupAnimationStyle">#android:style/Animation.PopupWindow</item>
</style>
If you want to change it - you need to override popup window style for your theme:
<style name="CustomActionBarTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle" tools:ignore="NewApi">#style/MyActionBar</item>
<item name="android:popupWindowStyle">#style/YourCustomStyle</item>
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<style name="YourCustomStyle" parent="#android:style/Widget.PopupWindow">
<item name="android:popupBackground">#drawable/your_background</item>
</style>
Alert dialog gets customized in the same way
OK I solved the problem. I passed the application context to both popup menu and alertdialog builder's constructor. This seems to cause problems with application themes. I simply changed getApplicationContext() to getActivity() and it worked.
I'm using HoloEverywhere and ActionbarSherlock to create my application. I've been successful in theming the listview i have in my main activity so that the color is grey instead of holo blue whenever pressed or focused. I would like to theme the preference options I have in a PreferenceActivity as well, but it only works for devices with pre-ICS. With devices running android 4.0+, whenever the option is pressed or focused, the color is still ICS blue.
Another question: I'm using a theme that's parent is Holo.Theme.Light.DarkActionBar. How would I make it so that it uses a light overflow popupmenu instead of the dark one? I've tried adding popupmenustyle to my styles, but I've had no luck
styles.xml:
<style name="Theme" parent="Holo.Theme.Light.DarkActionBar">
<item name="android:actionBarItemBackground">#drawable/selectable_background</item>
<item name="actionBarItemBackground">#drawable/selectable_background</item>
<item name="android:activatedBackgroundIndicator">#drawable/activated_background_holo_light</item>
<item name="activatedBackgroundIndicator">#drawable/activated_background_holo_light</item>
<item name="android:listChoiceBackgroundIndicator">#drawable/list_selector_holo_light</item>
<item name="android:actionBarStyle">#style/ActionBar</item>
<item name="actionBarStyle">#style/ActionBar</item>
</style>
<style name="ActionBar" parent="#style/Widget.Sherlock.Light.ActionBar.Solid.Inverse">
<item name="android:background">#666666</item>
<item name="android:icon">#drawable/icon</item>
<item name="background">#666666</item>
<item name="icon">#drawable/icon</item>
</style>
For me this works:
<item name="popupMenuStyle">#style/PopupMenu.Intellistats</item>
<item name="android:popupMenuStyle">#style/PopupMenu.Intellistats</item>
where:
<style name="PopupMenu.Intellistats" parent="#style/Holo.ListPopupWindow">
<item name="android:popupBackground">#color/holo_orange_dark</item>
</style>