I want to show a group of options in the menu, and need to change the standard three-lines icon to my own image. How can I achieve this? Group doesn't have an #icon option, unfortunately
menu.xml
<item
android:icon="#drawable/settings">
<group android:menuCategory="container">
<item
android:id="#+id/action_mute"
android:showAsAction="never"
android:title="#string/action_mute"/>
<item
android:id="#+id/action_add"
android:showAsAction="never"
android:title="#string/action_add"/>
<item
android:id="#+id/action_people"
android:showAsAction="never"
android:title="#string/action_people"/>
<item
android:id="#+id/action_more"
android:showAsAction="never"
android:title="#string/action_more"/>
</group>
</item>
It is called overflow button, if you want to change it you need to declare it in your style.xml located in the values folder.
Add this in your style.xml
<style name="Widget.ActionButton.Overflow" parent="#android:style/Widget.Holo.ActionButton.Overflow">
<item name="android:src">#drawable/your_drawable</item>
</style>
after you need to call it from you AppTheme
<style name="AppTheme" parent="//theme of your actionbar">
<item name="android:actionOverflowButtonStyle">#style/Widget.ActionButton.Overflow</item>
</style>
Related
I have have a group of items in a navigation drawer menu:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:title="Group Title">
<menu>
<group android:checkableBehavior="single">
<item
android:id="#+id/nav_camera"
android:icon="#drawable/ic_star_black_24dp"
android:title="Import" />
<item
android:id="#+id/nav_gallery"
android:icon="#drawable/ic_share_black_24dp"
android:title="Gallery" />
</group>
</menu>
</item>
</menu>
I managed to style the menu items following the instruction in this post from stack overflow. Basically modifying these three properties:
This works fine except it only styles the items inside the tag:
So my question is: how can I style (color and background) the titles ("Show Apps" and "Others")?
add following codes in styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:itemBackground">#00F</item>
<item name="android:itemTextAppearance">#style/TextAppearance</item>
</style>
<style name="TextAppearance">
<item name="android:textColor">#F00</item>
</style>
change first line "name" and "parent" with your app defaults
i try change background color option menu from black to white
but my code not work.i see this link too How to change background color popup menu android but its not work for me.
styles
<style name="Theme.DesignDemo" parent="Base.Theme.DesignDemo">
</style>
<style name="Base.Theme.DesignDemo" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/ColorPrimary</item>
<item name="popupMenuStyle">#style/PopupMenu</item>
<item name="colorPrimaryDark">#color/ColorPrimaryDark</item>
</style>
<style name="PopupMenu" parent="Widget.AppCompat.PopupMenu">
<item name="android:popupBackground">#android:color/white</item>
</style>
</resources>
popup_menu.xml:
<?xml version="1.0" encoding="utf-8" ?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
<!--///showAsAction="always" ///-->
<item android:id="#+id/action_settings" android:title="Share" showAsAction="always" />
<item android:id="#+id/action_settings1" android:title="Bluetooth" showAsAction="always" />
<item android:id="#+id/action_settings2" android:title="Exit" showAsAction="always" />
<!--/android:showAsAction="ifRoom"/-->
<item android:id="#+id/action_settings3" android:title="Share" android:showAsAction="ifRoom" />
<item android:id="#+id/action_settings4" android:title="Bluetooth" android:showAsAction="ifRoom" />
</menu>
How to change background color option menu
Have you controlled the context you passed to the constructor? When you create a PopupMenu class, please use the Activity context like this :
PopupMenu popup = new PopupMenu(this, anchorView);//Not BaseContext
Whether you use android.widget.PopupMenu or android.support.v7.widget.PopupMenu? They governed by different theme attributes :
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- if using android.widget.PopupMenu -->
<item name="android:popupMenuStyle">#style/PopupMenu</item>
<!-- if using android.support.v7.widget.PopupMenu -->
<item name="popupMenuStyle">#style/PopupMenu</item>
</style/>
<style name="PopupMenu" parent="Widget.AppCompat.PopupMenu">
<item name="android:popupBackground">#android:color/white</item>
</style>
Effect like this.
How to change the text color of submenu in Android? I customize the application theme and override the relative attributes, but it still doesn't work. My menu has two submenus, which are initially hidden, when clicked, it shows. However, the style of submenus can't be modified, while the title of action bar can. This question bothers me all the day, I almost try every ways I find.
This is my code!
menu.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.classsignin.MainActivity" >
<item
android:id="#+id/action_overflow"
android:title="分享"
android:icon="#drawable/drop_select"
android:showAsAction="always"
>
<menu >
<item
android:id="#+id/absent"
android:title="请假"
android:icon="#drawable/absent"
/>
<item
android:id="#+id/refresh"
android:title="刷新课程"
android:icon="#drawable/refresh"
/>
</menu>
</item>
styles.xml
<style name="CustomTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBarTheme</item>
<item name="android:actionMenuTextAppearance">#style/MyActionBarMenu</item>
<item name="android:actionMenuTextColor">#color/blue</item>
<item name="android:homeAsUpIndicator">#drawable/back</item>
<item name="android:spinnerItemStyle">#style/MySpinnerItem</item>
</style>
<style name="MyActionBarTheme" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#color/white</item>
<item name="android:titleTextStyle">#style/MyActionBarTitle</item>
</style>
<style name="MyActionBarTitle" parent="#android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textSize">16sp</item>
<item name="android:textColor">#color/blue</item>
</style>
<style name="MyActionBarMenu" parent="#android:style/TextAppearance.Holo.Widget.ActionBar.Menu">
<item name="android:textSize">16sp</item>
<item name="android:textColor">#color/blue</item>
</style>
<style name="MySpinnerItem" parent="#android:style/Widget.Holo.TextView.SpinnerItem">
<item name="android:textAppearance">#style/MyTextAppearance</item>
</style>
<style name="MyTextAppearance" parent="#android:style/TextAppearance.Holo.Widget.TextView.SpinnerItem">
<item name="android:textColor">#color/blue</item>
</style>
Essentially you will want to customise your MenuItem's style by having the android:itemBackground attribute overridden with your custom color/drawable selector in your style.xml and as well a vtextColor` attribute to override.
In case your menu has also submenu's, then you will want as well to style the header title of the submenu, which usually is automatically with White background by overriding the attribute actionBarPopupTheme with your custom style.
style.xml
<resources>
<style name="AppTheme" parent="Theme.AppCompat.DayNight.DarkActionBar">
<item name="android:itemBackground">#drawable/menu_popup_selector</item>
<item name="actionBarPopupTheme">#style/SubmenuHeaderStyle</item>
</style>
<style name="SubmenuHeaderStyle" parent="ThemeOverlay.AppCompat.Light">
<item name="android:colorBackground">#color/colorPrimary</item>
<item name="android:textColor">#color/colorAccent</item>
</style>
</resources>
menu_popup_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<color
android:color="#color/colorPrimary"/>
</item>
<item>
<color
android:color="#655611"/>
</item>
</selector>
And you will have something like those screenshots
(1st menu and then the submenu after clicking one item on the 1st menu - the pink header is my submenu header).
Just for you to know when I have the normal menu without submenu would look like this hierarchy views:
<menu>
<item/>
<item/>
<item/>
</menu>
and a menu with submenu as this example of hierarchy views:
<menu>
<item/>
<item/>
<group>
<item>
<menu>
item
item
item
</menu>
</item>
</group>
<item/>
<item/>
</menu>
In the toolbar's dropdown option menu, does anyone know how to add left side check mark in the menu item?
It is similar behavior as to use <group>, but the <group> gives a default radio button in the right side of the menu item. Thanks!
You can use setGroupCheckable()
EDIT-1:
use the following code:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="all">
<item android:id="#+id/red"
android:title="#string/red" />
<item android:id="#+id/blue"
android:title="#string/blue" />
</group>
</menu>
The checkableBehavior="all" converts it into checkboxes.
Edit-2:
I had posted the following code somewhere.. Refer to get started on how to customize action bar menu items :
in your style file, place the following:
<style name="MyAppTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:titleTextStyle">#style/MyActionBar.TitleTextStyle
<item name="android:actionMenuTextAppearance">#style/MyActionBar.MenuTextStyle</item>
<item name="android:actionMenuTextColor">#color/action_bar_red</item> </style>
<style name="MyActionBar.TitleTextStyle" parent="android:style/TextAppearance.Holo.Widget.ActionBar.Title"> <item name="android:textColor">#F0F</item> <item name="android:textStyle">bold</item>
<item name="android:textSize">24dip</item> </style>
<style name="MyActionBar.MenuTextStyle" parent="android:style/TextAppearance.Holo.Widget.ActionBar.Menu"> <item name="android:textColor">#F0F</item> <item name="android:textStyle">bold</item>
<item name="android:textSize">24dip</item>
</style>
You can make changes in the above style items to suit your requirements. I have not added separate styling for color though. As you might observe, I am just assigning red color (which I have declared in my colors file) to it. You may change as required.
I am working on an app that uses a theme that extends #style/Theme.AppCompat.Light.DarkActionBar.
On one of my activities, there is an Action Bar icon that shows three options with radiobuttons (here's an extract from the menu XML file):
<item
android:icon="#drawable/ic_action_filter_white"
android:showAsAction="always"
android:title=""
preparatest:showAsAction="always">
<menu>
<group android:checkableBehavior="single" >
<item
android:id="#+id/menu_filter_all"
android:title="#string/history_list_filter_all"
android:checked="true"/>
<item
android:id="#+id/menu_filter_pending"
android:title="#string/history_list_filter_pending"/>
<item
android:id="#+id/menu_filter_finished"
android:title="#string/history_list_filter_finished"/>
</group>
</menu>
</item>
I want to give these radiobuttons a custom style, but I don't know where to do it. On my styles.xml file I have defined the custom style as
<style name="RadioButtonPTGreenTheme" parent="android:Widget.CompoundButton.RadioButton">
<item name="android:button">#drawable/ptgreentheme_btn_radio_holo_light</item>
</style>
and tried using all these four options, but to no avail:
<item name="android:radioButtonStyle">#style/RadioButtonPTGreenTheme</item>
<item name="android:listChoiceIndicatorSingle">#style/RadioButtonPTGreenTheme</item>
<item name="android:radioButtonStyle">#drawable/ptgreentheme_btn_radio_holo_light</item>
<item name="android:listChoiceIndicatorSingle">#drawable/ptgreentheme_btn_radio_holo_light</item>
Does anyone know how to do this? Thanks!
See this blog post for a way to do it.
Long story short, android:actionBarWidgetTheme is used to style elements that depend on the Action Bar, so the android:radioButtonStyle should be put inside a style for actionBarWidgetTheme:
<style name="MyTheme" parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarWidgetTheme">#style/MyActionBarWidgetTheme</item>
</style>
<style name="MyActionBarWidgetTheme" parent="#android:style/Theme.Holo">
<item name="android:radioButtonStyle">#style/MyRadioButtonStyle</item>
</style>