Change Background Color Popupmenu on NoActionBar - android

I still haven't found the correct solution to change the background color for PopupMenu. But in this case i am using AppTheme.NoActionBar for particular reason. Here's my style
<style name="DarkThemeNoAppBar" parent="AppTheme.NoActionBar">
<item name="backgroundcolor">#3d3b3b</item>
<item name="cardbackground">#5e5b5b</item>
<item name="textcolor">#ede7e7</item>
<item name="textcolordrawer">#faf6f6</item>
<item name="tintcolor">#d9d4d4</item>
<item name="buttoncolor">#45b6ac</item>
<item name="texttitlecolor">#ede7e7</item>
<item name="backgroundcolorlayout">#181818</item>
<item name="android:itemBackground">#181818</item>
<item name="android:textColor">#ede7e7</item>
<item name="popupMenuStyle">#style/popupMenuDarkStyle</item>
</style>
<style name="popupMenuDarkStyle" parent="Widget.AppCompat.PopupMenu">
<item name="android:popupBackground">#181818</item>
</style>
If you see popupMenuStyle, this popupMenuDarkStyle does not give any effect in UI. Many literature in google solve this problem but it only for Theme.AppCompat.Light.DarkActionBar but in my case i need to use AppTheme.NoActionBar. Please someone give me some advice.
UPDATE 2
this below is the second attempt
<style name="DarkThemeNoAppBar" parent="AppTheme.NoActionBar">
<item name="backgroundcolor">#3d3b3b</item>
<item name="cardbackground">#5e5b5b</item>
<item name="textcolor">#ede7e7</item>
<item name="textcolordrawer">#faf6f6</item>
<item name="tintcolor">#d9d4d4</item>
<item name="buttoncolor">#45b6ac</item>
<item name="texttitlecolor">#ede7e7</item>
<item name="backgroundcolorlayout">#181818</item>
<item name="android:itemBackground">#181818</item>
<item name="android:textColor">#ede7e7</item>
<item name="android:popupMenuStyle">#style/popupMenuDarkStyle</item>
</style>
<style name="popupMenuDarkStyle" parent="ThemeOverlay.AppCompat.Light">
<item name="android:popupBackground">#181818</item>
</style>
My PopupMenu is attached on optionMenu (on Burger button), here how optionsMenu created in Activity.
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Manual add menu
menu.add(0, 1, 1, DesignUtil.menuIconWithText(getResources()
.getDrawable(R.drawable.ic_bookmark_black), "Bookmark"));
menu.add(0, 2, 1, DesignUtil.menuIconWithText(getResources()
.getDrawable(R.drawable.ic_settings_black_24dp), "Settings"));
return true;
}
Yes, popupmenu display correctly but the background color still can not be changed

Try this, it works for me
step 1.create new style
<style name="popupMenuStyle" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:textColor">#2FAC7E</item>
<item name="android:textSize">18sp</item>
<item name="android:itemBackground">#181818</item>
</style>
step 2.add this line in your activity where you add PopUpMenu
Context wrapper = new ContextThemeWrapper(activity, R.style.popupMenuStyle);
final PopupMenu popup = new PopupMenu(wrapper, view);

It work for me when i created menu by using onCreateOptionMenu,try this
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:itemBackground">#181818</item>
<item name="android:textColor">#color/colorAccent</item>
<item name="android:windowIsTranslucent">true</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="windowActionBar">false</item>
</style>

This worked for me:
<style name="DarkThemeNoAppBar" parent="AppTheme.NoActionBar">
<item name="backgroundcolor">#3d3b3b</item>
<item name="cardbackground">#5e5b5b</item>
<item name="textcolor">#ede7e7</item>
<item name="textcolordrawer">#faf6f6</item>
<item name="tintcolor">#d9d4d4</item>
<item name="buttoncolor">#45b6ac</item>
<item name="texttitlecolor">#ede7e7</item>
<item name="backgroundcolorlayout">#181818</item>
<item name="android:itemBackground">#181818</item>
<item name="android:textColor">#ede7e7</item>
<!--The "android:" prefix is for a regular widget, such as android.widget.PopupMenu,
while the ones without this prefix are for the support library versions of these widgets-->
<item name="popupMenuStyle">#style/popupMenuDarkStyle</item>
<item name="android:popupMenuStyle">#style/popupMenuDarkStyle</item>
</style>
<style name="popupMenuDarkStyle" parent="ThemeOverlay.AppCompat.Light">
<item name="android:popupBackground">#181818</item>
</style>
Using ThemeOverlay.AppCompat.Light as the parent might not be necessary, but I included it because that's how mine is set up and it works. The key is probably android:popupMenuStyle rather than popupMenuStyle.

Related

Android popup menu "two backgrounds"

I have attached the screenshot showing what I want to achieve. I want to achieve just one background for my popup menu. Now as you can see on the picture below my menu there is a second background? I want toi stay this one below (darker one) with rounded corners. How to fix this?
I am adding my style.xml
<style name="objectsmeasure_dark" parent="Theme.MaterialComponents.NoActionBar">
<item name="colorPrimary">#color/a212121</item>
<item name="colorPrimaryDark">#android:color/black</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:alertDialogTheme">#style/alert_dialog_dark</item>
<item name="android:windowBackground">#color/colorWindowBackgroundNight</item>
<item name="colorBg">#color/colorWindowBackgroundNight</item>
<item name="colorBottomNavigationViewBg">#color/bottom_nav_view_bg_night</item>
<item name="colorBottomNavigationViewItem">#color/bottom_nav_view_item_night</item>
<item name="android:popupMenuStyle">#style/popup_menu_dark</item>
<item name="popupMenuStyle">#style/popup_menu_dark</item>
<item name="myBackgroundColor">#color/colorGrey</item>
<item name="myEtBackgroundColor">#color/BF606060</item>
<item name="myCardBackground">#color/a212121</item>
<item name="myTextColor">#android:color/white</item>
<item name="myTintColor">#android:color/white</item>
<item name="myButtonColor">#color/colorButton</item>
<item name="myHintTextColor">#color/B3FFFFFF</item>
<item name="android:navigationBarColor">#android:color/black</item>
<item name="dialogTheme">#style/dialog_dark</item>
<item name="android:dialogTheme">#style/dialog_dark</item>
<item name="android:windowContentTransitions">true</item>
<item name="currentTheme">#style/objectsmeasure_dark</item>
</style>
<style name="popup_menu_dark" parent="Widget.AppCompat.PopupMenu">
<item name="android:popupBackground">#color/dark</item>
</style>
<style name="alert_dialog_dark" parent="Theme.MaterialComponents.Dialog.Alert">
<item name="colorPrimary">#color/colorButton</item>
<item name="android:textColor">#android:color/white</item>
<item name="android:textColorPrimary">#android:color/white</item>
<item name="android:background">#color/dark</item>
<item name="background">#color/dark</item>
<item name="buttonBarPositiveButtonStyle">#style/alert_dialog_button_positive</item>
<item name="buttonBarNegativeButtonStyle">#style/alert_dialog_button_negative</item>
</style>
<style name="dialog_dark" parent="Theme.MaterialComponents.Dialog">
<item name="colorPrimary">#color/colorButton</item>
<item name="android:textColor">#android:color/white</item>
<item name="android:textColorPrimary">#android:color/white</item>
<item name="android:background">#color/dark</item>
<item name="background">#color/dark</item>
<item name="buttonBarPositiveButtonStyle">#style/alert_dialog_button_positive</item>
<item name="buttonBarNegativeButtonStyle">#style/alert_dialog_button_negative</item>
</style>
Thank you for any help.
I solved this issue. It turned out I mixed parent styles - MaterialComponents and AppCompat and once I standarize it the problem was gone.

How to set text and/or background color of Cut Copy Paste

I am using a custom Dark Theme in my app. Everything is doing okay, except for the Cut Copy Paste dialog that appears as a solid black square.
Surely there is a style that determines that, but I can't find it, or an answer that addresses this directly. Min API is 16.
<style name="DarkTheme" parent="AppTheme.NoActionBar">
<item name="colorPrimary">#color/blackBackground</item>
<item name="colorPrimaryDark">#color/blackBackground</item>
<item name="colorAccent">#color/yellow</item>
<item name="android:textColor">#color/whiteText</item>
<item name="android:background">#color/blackBackground</item>
<item name="buttonStyle">#style/darkButtonStyle</item>
<item name="spinnerStyle">#style/darkSpinnerStyle</item>
</style>
<style name="darkButtonStyle" parent="#android:style/Widget.Button">
<item name="android:layout_width">fill_parent</item>
<item name="android:textColor">#color/whiteText</item>
<item name="android:textSize">16sp</item>
<item name="android:padding">10dp</item>
<item name="android:textStyle">bold</item>
<item name="android:background">#color/darkBackground</item>
<item name="android:gravity">center</item>
<item name="android:textAllCaps">true</item>
</style>
<style name="darkSpinnerStyle" parent="Widget.AppCompat.Spinner">
<item name="android:background">#color/blackBackground</item>
<item name="android:paddingTop">0dp</item>
<item name="android:layout_marginStart">1dp</item>
<item name="android:layout_marginLeft">1dp</item>
<item name="android:layout_width">0dp</item>
<item name="android:layout_height">0dp</item>
</style>
I was having the same issue when regarding to MaterialAlertDialog. I was able to fix it using backgroundTint instead of background in styles. This is how:
Before
<style name="materialAlertDialog" parent="ThemeOverlay.MaterialComponents.MaterialAlertDialog">
<item name="android:background">#color/colorPrimaryDark</item>
<item name="materialAlertDialogTitleTextStyle">#style/TitleTextStyle</item>
<item name="materialAlertDialogBodyTextStyle">#style/BodyTextStyle</item>
<item name="buttonBarPositiveButtonStyle">#style/PositiveButtonStyle</item>
<item name="buttonBarNegativeButtonStyle">#style/NegativeButtonStyle</item>
</style>
This will be enough to repropduce the error that you are saying... So what i did was changing background for backgroundTint...
After
<style name="materialAlertDialog" parent="ThemeOverlay.MaterialComponents.MaterialAlertDialog">
<item name="android:backgroundTint">#color/colorPrimaryDark</item>
<item name="materialAlertDialogTitleTextStyle">#style/TitleTextStyle</item>
<item name="materialAlertDialogBodyTextStyle">#style/BodyTextStyle</item>
<item name="buttonBarPositiveButtonStyle">#style/PositiveButtonStyle</item>
<item name="buttonBarNegativeButtonStyle">#style/NegativeButtonStyle</item>
</style>
It seems like when you set a background and the dialog is created, the toolbar of copy/paste menu was changing his background in some weird way that i cant explain.
So this is not the exact answer for your problem but it may help you.
Note: Try removing background attr of your style. I have a dark theme and there is no need to use it. Just simple use <style name="AppTheme" parent="Theme.MaterialComponents.DayNight"> instead of <style name="DarkTheme" parent="AppTheme.NoActionBar">.

Action bar popup background is not changing

#style/Theme.MyAppTheme.ActionBar
<item name="android:popupMenuStyle">#style/popupMenuStyle</item>
<item name="android:actionBarWidgetTheme">#style/Theme.MyTheme.Widget</item>
<item name="android:actionBarItemBackground">#null</item>
<item name="android:listPreferredItemHeightSmall">45dp</item>
<style name="popupMenuStyle" parent="#android:style/Widget.PopupMenu">
<item name="android:popupBackground">#android:color/white</item>
</style>
<style name="Theme.MyTheme.Widget" parent="#android:style/Theme.Holo">
<item name="android:textColor">#0675bc</item>
<item name="android:background">#android:color/white</item>
</style>
I have an activity which is having action bar overflow menu and my custom pop up menu I am using Theme.MyTheme.Widget in the above code it is working fine but the problem is I am using search view in action bar in another activity.Now the problem is if I am using the above code to change the overflow menu background this changes are applying to the search bar also which I don't need
if you API is minimum API level 14 , you can change with this (worked for me).
<style name="Theme.myapp" parent="#style/Theme.Light.DarkActionBar">
<item name="android:actionDropDownStyle">#style/myapp_DropDownNav</item>
<item name="android:actionBarWidgetTheme">#style/myapp.actionBarWidgetTheme</item>
</style>
<style name="myapp.actionBarWidgetTheme" parent="#style/Theme.">
<item name="android:spinnerDropDownItemStyle">#style/myapp.Widget.DropDownItem.Spinner</item>
</style>
<style name="myapp_DropDownNav" parent="#style/Widget.Spinner.DropDown.ActionBar">
<item name="background">#drawable/spinner_background_ab_myapp</item>
<item name="android:background">#drawable/spinner_background_ab_myapp</item>
<item name="android:popupBackground">#drawable/menu_dropdown_panel_myapp</item>
<item name="android:dropDownSelector">#drawable/selectable_background_myapp</item>
</style>
<style name="myapp.Widget.DropDownItem.Spinner" parent="Widget.DropDownItem.Spinner">
<item name="android:textAppearance">#style/myapp.TextAppearance.Widget.DropDownItem</item>
</style>
<style name="myapp.TextAppearance.Widget.DropDownItem" parent="TextAppearance.Widget.DropDownItem">
<item name="android:textColor">#color/black</item>
</style>
if you are using ActionBarSherlock (minimun API level 9), try this:
<style name="Theme.yourapp" parent="#style/Theme.Sherlock.Light">
<item name="popupMenuStyle">#style/PopupMenu.Style</item>
<item name="dropDownListViewStyle">#style/DropDownListView.Style</item> </style>
<style name="PopupMenu.Style" parent="#style/Widget.Sherlock.Light.ListPopupWindow">
<item name="android:popupBackground">#drawable/your_background</item>
</style>
<style name="DropDownListView.Style" parent="#style/Widget.Sherlock.Light.ListView.DropDown">
<item name="android:listSelector">#drawable/your_background</item>
</style>
Hope it helps you!!

How to change divider color option menu item?

I want to change default divider color of my option menu, so can give me some suggestion or technical?
Its working for me in Navigationmenu.
This below line is mandatory.
<item name="android:listDivider">#color/white</item>
//This is ur style
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:listDivider">#color/white</item>
</style>
//This is ur menu item.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:id="#+id/nav_profile"
android:icon="#drawable/m_profile"
android:title="#string/my_profile" />
<group android:id="#+id/my_id">
<item
android:id="#+id/nav_coming"
android:icon="#drawable/m_coming"
android:title="#string/comingsoon" />
</group>
</group>
</menu>
you can do it by setting theme to your popup menu
use below code in your style.xml file in res folder
<style name="MyThemePopup" parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:textColor">#color/white</item>
<item name="android:dividerHeight">2px</item>
<item name="android:divider">#F00</item>
<item name="android:popupMenuStyle">#style/PopupMenu</item>
</style>
<style name="PopupMenu" parent="#android:style/Widget.PopupMenu">
<item name="android:popupBackground">#color/opaque_black_color_dark</item>
</style>
above code is for creating theme where <item name="android:divider">#F00</item> is use for setting color to divider
after that you can set created theme to your activity in which popup menu is present through manifest file
<activity
android:name="com.android.MainActivity"
android:theme="#style/MyThemePopup" />
hope this code will help you to achieve your requirement happy coding :)
Does nothing for me, maybe because of the appCompat version?
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="android:dividerHeight">2dp</item>
<item name="android:divider">#color/ucc_blue</item>
</style>
It doesn't matter if i put it in the MyActionBar style or in the AppTheme style both won't work. But setting the divider height does make my OptionMenu scrollable....
Maybe it doesn't work because they are subMenuItems?
add this item to the app theme:
<style name="theme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:dropDownListViewStyle">#style/MyDropDownListView</item>
</style>
<style name="MyDropDownListView" parent="#android:style/Widget.ListView.DropDown">
<item name="android:divider">#color/transparent</item>
</style>
For those who have not found the answer yet for this problem, this is how it worked for me and hope it will work for you as well:
<style name="PopupMenu">
<item name="android:itemBackground">#color/background_medium_gray</item>
<item name="android:background">#android:color/transparent</item>
<item name="android:textColor">#android:color/black</item>
<item name="android:colorBackground">#color/BackgroundGray</item>
<item name="android:dividerHeight">1dp</item>
</style>
Context context = new ContextThemeWrapper(getActivity(), R.style.PopupMenu);
final PopupMenu popupMenu = new PopupMenu(context, view);
final MenuInflater menuInflater = popupMenu.getMenuInflater();

App Theme not applied when entering search mode on Samsung

I have a strange behaviour on Samsung devices (Galaxy S4, Galaxy Note, ...). In our App we have a themed Actionbar (using ActionbarCompat) with a search interface. Basically we followed the tutorial here: http://developer.android.com/guide/topics/search/search-dialog.html
This is the default look of our Actionbar which works fine:
Furthermore, if i touch the search icon the theme is also applied and works well:
But if I do a long press on the menu button of Samsung devices, the search will be opened with an default theme:
I already added the theme in our (custom)-Application class, but no change appears.
#Override
public void onCreate() {
super.onCreate();
setTheme(R.style.ClassicTheme);
}
How can I avoid this strange behaviour? Do I have to add something to our styles?
This is my basic theme:
<style name="ClassicTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="themeIdentifier">classic</item>
<item name="android:windowBackground">#color/grey_default</item>
<item name="popupMenuStyle">#style/ClassicTheme.PopupMenu</item>
<item name="textAppearanceLargePopupMenu">
#style/ClassicTheme.PopupMenuTextAppearanceLarge
</item>
<item name="textAppearanceSmallPopupMenu">
#style/ClassicTheme.PopupMenuTextAppearanceSmall
</item>
<item name="android:popupMenuStyle">#style/ClassicTheme.PopupMenu</item>
<item name="actionBarSearchIcon">#drawable/ic_classic_menu_search</item>
<item name="actionBarSearchBackground">#drawable/textfield_classic_ab</item>
<item name="actionBarToggler">#drawable/ic_classic_menu_menu_left</item>
<item name="android:actionBarStyle">#style/ClassicTheme.ActionBar</item>
<item name="android:dropDownListViewStyle">#style/ClassicTheme.DropDownListView</item>
<item name="dropDownListViewStyle">#style/ClassicTheme.DropDownListView</item>
<item name="android:actionDropDownStyle">#style/ClassicTheme.DropDownNav</item>
<item name="android:actionBarWidgetTheme">#style/ClassicTheme.Widget</item>
<item name="android:actionOverflowButtonStyle">#style/ClassicTheme.OverFlow</item>
<item name="android:actionBarItemBackground">#drawable/selector_classic_simple_fast</item>
<item name="android:spinnerItemStyle">#style/ClassicTheme.SpinnerItemStyle</item>>
</style>
<style name="ClassicTheme.SpinnerItemStyle" parent="#android:style/Widget.TextView.SpinnerItem">
<item name="android:textColor">#android:color/white</item>
</style>
<style name="ClassicTheme.ActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/grey_darker</item>
<item name="android:backgroundStacked">#color/grey_darker</item>
<item name="android:backgroundSplit">#color/grey_darker</item>
<item name="android:progressBarStyle">#color/grey_darker</item>
</style>
<style name="ClassicTheme.ListPopupMenu" parent="#style/Widget.AppCompat.ListPopupWindow">
<item name="android:popupBackground">#drawable/bg_classic_menu_dropdown</item>
</style>
<style name="ClassicTheme.DropDownListView" parent="#style/Widget.AppCompat.ListView.DropDown">
<item name="android:listSelector">#drawable/selector_classic_simple</item>
<item name="android:divider">#color/grey_divider</item>
<item name="android:dividerHeight">1dp</item>
</style>
<!--<item name="android:background">#drawable/spinner_background_ab_ClassicTheme</item>-->
<style name="ClassicTheme.DropDownNav" parent="#style/Widget.AppCompat.Spinner.DropDown.ActionBar">
<item name="android:background">#drawable/selector_classic_spinner_ab</item>
<item name="android:popupBackground">#drawable/bg_classic_menu_dropdown</item>
<item name="android:dropDownSelector">#drawable/selector_classic_simple</item>
<item name="android:textColor">#android:color/white</item>
</style>
<!-- this style is only referenced in a Light.DarkActionBar based theme -->
<style name="ClassicTheme.Widget" parent="#style/Theme.AppCompat">
<item name="android:popupMenuStyle">#style/ClassicTheme.PopupMenu</item>
<item name="android:dropDownListViewStyle">#style/ClassicTheme.DropDownListView</item>
<item name="searchViewAutoCompleteTextView">#style/ClassicTheme.SearchViewStyle</item>
<item name="textAppearanceSearchResultSubtitle">#style/ClassicTheme.SearchSuggestionSubtitleStyle</item>
</style>
<style name="ClassicTheme.OverFlow" parent="#style/Widget.AppCompat.ActionButton.Overflow">
<item name="android:src">#drawable/ic_classic_menu_overflow</item>
</style>
<style name="ClassicTheme.PopupMenu" parent="#style/Widget.AppCompat.PopupMenu">
<item name="android:popupBackground">#drawable/bg_classic_menu_dropdown</item>
<item name="android:textColor">#android:color/white</item>
</style>
<style name="ClassicTheme.PopupMenuTextAppearanceSmall" parent="#style/TextAppearance.AppCompat.Widget.PopupMenu.Small">
<item name="android:textColor">#android:color/white</item>
</style>
<style name="ClassicTheme.PopupMenuTextAppearanceLarge" parent="#style/TextAppearance.AppCompat.Widget.PopupMenu.Large">
<item name="android:textColor">#android:color/white</item>
</style>
</resources>
Update 21.07.2014: I tried to add actionModeBackground-attribute in my style:
<item name="actionModeBackground">#drawable/cab_background_top_example</item>
<item name="android:actionModeBackground">#drawable/cab_background_top_example</item>
But this will only change the look of the actionbar, if I make a selection in a listview. Long-Pressing the menu button keeps the actionbar white.
Furthermore I investigated some time in Android search_bar.xml resource. (https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/res/res/layout/search_bar.xml)
In this file the background will be configured by actionModeBackground-Attribute, but I do not have any idea, why this does not work in my special case.
I finally solved this problem by overriding the startSearch(...)-Method of Activity class and expand the Search-MenuItem programmatically if not already open.
#Override
public void startSearch(String initialQuery, boolean selectInitialQuery, Bundle appSearchData,
boolean globalSearch) {
// menuItemSearch-class attribute will be set up in onCreateOptionsMenu(...)
if (menuItemSearch == null || globalSearch) {
super.startSearch(initialQuery, selectInitialQuery, appSearchData, globalSearch);
return;
}
if (!menuItemSearch.isActionViewExpanded()) {
menuItemSearch.expandActionView();
}
}

Categories

Resources