How to set the background for popup menu? - android

I want to set the background of my popup menu like in the given image:
Is there any way to set this background for the given popup menu in android? If anyone have any idea please help me in accomplishing this.

you can style your pop-up menu in the xml file
Like this:
I simply change the color to #ffffff means Hex white!
<style name="style" parent="android:Theme.Holo.Light">
<item name="android:popupMenuStyle">...</item>
<item name="android:popupAnimationStyle">...</item>
<item name="android:popupBackground">#ffff</item>
<!-- etc etc -->

Related

How to change to text colour of the Cut/Copy/Paste popup menu

I have the following in my styles.xml
<style name="dialog_style" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorAccent">#ffaaaa00</item>
<item name="android:background">#ff444400</item>
<item name="android:textColorPrimary">#ffa25600</item>
</style>
(The horrible colours are for testing only!)
This gives the following
What I want is a dark/black background but when I do that, the text is unreadable.
Q: How do I change the text colour of "Cut", "Copy"...?
tia,
Kevin
I think it's a little bit better solution than user3247782's,
<style name="CustomAlertDialog" parent="Theme.AppCompat.Light.Dialog.Alert">
...
<item name="android:popupBackground">#android:color/transparent</item>
</style>
You can change them by following style names:
<item name="colorAccent">#color/twoCuteSelectionHandlersColor</item>
<item name="android:textColorHighlight">#color/selectionColor</item>
Also you can set highlight color directly for pacific EditText using android:textColorHighlight attribute in xml layout or programmatically:
et.setHighlightColor(color);
For context menu you need create your own context menu. check this question for how disabling default context menu and implementing custom menu.
This isn't really an answer. The black-on-black edit menu is only generated from an EditText contained in an AlertDialog. The same code in a Fragment gives black-on-white.
So I "solved" my problem by converting the AlertDialog into a Fragment.
The original question, though, is still unanswered.
Alert Dialog and Popup Menu generaly take the color of #ColorAccent as the background. So try changing the colorAccent or just inflate a custom xml with the specifications you want.
Just change the parent of it from Theme.Material.Light to Theme.Material .
It will make the text white, there.
I fixed it by setting a background color with opacity in the style of the alertdialog
In styles.xml
<style name="AppCompatAlertDialogStyle">
...
<item name="android:background">#color/black_overlay</item>
...
</style>
In colors.xml
<color name="black_overlay">#66000000</color>
If you use MaterialAlertDialogBuilder then you can define background color through colorSurface attribute.
Then in styles you can just set background to transparent.
android:background="#android:color/transparent"
Dialog will use the one define in colorSurface and "copy/paste" will use default system colors (e.g. white).

How to change Options menu dots color for the theme "Theme.AppCompat.Light.NoActionBar"

To change the default option menu icon color(3 vertical dote), i have tried adding
<item name="android:textColorSecondary">#color/white</item>
But it doesn't make any change. I think it is not working coz my AppTheme parent is Theme.AppCompat.Light.NoActionBar. So can anybody help me on this?
The easiest way of doing it is by adding
<item name="popupTheme">#style/ThemeOverlay.AppCompat.Light</item>
or
<item name="popupTheme">#style/ThemeOverlay.AppCompat.Dark</item>
to your primary Theme in order to change it to light or dark.
EDIT: In order to add any color for the overflow icon you would have to override the actionOverflowButtonStyle like so:
<style name="Theme.MyAppTheme" parent="Theme.AppCompat.NoActionBar">
<item name="actionOverflowButtonStyle">#style/OverFlow</item>
</style>
<style name="OverFlow" parent="#style/Widget.AppCompat.Light.ActionButton.Overflow">
<item name="android:src">#drawable/ic_overflow_icon</item>
</style>
You can easily create your own overflow icon from websites like Android Asset Studio
2019 - Easiest way to do is write the below code to your xml in toolbar code or where you want.
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
please give up vote if its work.
You can Either use your own drawable or get the default overFlowIcon and change its tint value like below:
bd.toolbar.overflowIcon?.setTint(Color.WHITE)
To change the drawable all together, you just have to create your own vector and set it like below:
bd.toolbar.overflowIcon = ContextCompat.getDrawable(this,R.drawable.ic_baseline_menu_24)
If you are using Toolbar, just add the following code in your Activity:
toolbar.setOverflowIcon(getDrawable(R.drawable.ic_more_vert_black_24dp));
By using this code, you can directly replace the "three dots" icon with any other icon of your choice. It worked for me.

How to change Background color of menuItem in android?

I am working on programmatically add a menu-Item into menu. I want to add background color on selection to particular Item. How can I add background to menuItem?
Your answer would be appreciated.
While other answers provide change style (which will affect all menu items, and, as I understand, need is to change one menu item),I propose you to use android:actionLayout attribute to implement your custom layour for menu item.
See documentation for it (search actionLayout there, it's very simple actually).
Also I think there is a possibility to make a selector as your layout and use it.
Update. Sorry, I mislead you :(
All of this will work only if MenuItem is shown as Action (not when pressing on three dots).
Seems like guys given other answers were right - the only way to customize this is changing themes.
But please check this and this - it might help you to provide selector for your purpose.
Also you can create PopupMenu or even PopupWindow, last one is fully customizable.
The last option is to create custom Spinner, check this.
Hope something from this will help you. Thanks.
Firstly You need to create an Style for popmenu as you want refer below sample for that
<style name="MyApp.PopupMenu" parent="android:Widget.Holo.Light.ListPopupWindow">
<item name="android:textStyle">#style/commonEditTextTheme</item>
<item name="android:popupBackground">#drawable/pop_up_menu_bg_with_shadow</item>
</style>
Place of drawable you can also replace with color as you needed or make XML Drawable into your drawable folder
<style name="commonEditTextTheme" parent="#android:style/TextAppearance.Medium">
<item name="android:fontFamily">sans-serif-light</item>
</style>
this pop menu theme add in your main application or activity theme like below
<!--My Theme-->
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
......
<item name="android:popupMenuStyle">#style/MyApp.PopupMenu</item>
</style>

Modifying the default window title in Android for a tablet?

I am looking for a way to slightly modify the default window title in an Android app for both phone and tablet. The example below is a tablet view of the title bar as standard:
I have tried implementing a custom title bar, which works but the context menu (circled in red) disappears, which I need. All I want to do is change the color of the bottom border or remove the bottom border altogether.
Is there a way to make changes whilst keeping the context menu?
Thanks
In your manifest in application tag define as :
android:theme="#style/mytheme"
Now in res/values you can define a file say theme.xml with content as :
<resources>
<style name="mytheme" parent="#android:style/Theme" >
<item name="android:_DEFAULT_BASE_COLOR_1">#XXXXXX</item>
<item name="android:windowNoTitle">true</item>
... .
</style>
</resources>
This will change the basic colour scheme of your application. Here are the color themes primarily used on Android: http://developer.android.com/design/style/color.html

styling ActionbarSherlock: textColor of the action-items

I was changing the background of the Actionbar in my App and to make text readable again I have to change the color of the text. I was successful with title/subtitle and the tab-texts, but I am struggling with the text of the action-items - they stay white no matter what I tried . Anyone has a hint on how to do that?
Also the overflow-icon is white which does not look too good on the wooden background - is that an extremely good reason to use the stuff below? I am not really sure what's the reason to not do it, but as I do not have a big device-test-park I better want to be sure ;-)
<!-- the following can be used to style the overflow menu button
only do this if you have an *extremely* good reason to!! -->
<!--<style name="MyOverflowButton" parent="Widget.Sherlock.ActionButton.Overflow">
<item name="android:src">#drawable/ic_menu_view</item>
<item name="android:background">#drawable/action_button_background</item>
</style>-->
I also struggled with this, but the solution to changing action item text color was:
<style name="My.Theme" parent="Theme.Sherlock.Light">
<item name="android:actionMenuTextColor">#android:color/white</item>
</style>
The key here was to use this attribute in the general theme, not in the actionbar style.
Try starting with android:theme="#style/Theme.Sherlock.Light" in your Manifest and then changing your styles. The light theme features dark action items. Or just look through the light theme to find out how to change them.

Categories

Resources