change the android actionbar submenu text color - android

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>

Related

How to change background color option menu xamarin android

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.

Styling popup menu item's

I am trying to style the items of my popup so they look like a list of buttons below eachother. The only problem is that I can't get to change anything of the popup items. I have tried to set a global popupMenuStyle in my app style but that didn't to anything. I tried to set an actionLayout on the menu items but still no change.
How can I change the styling of my popup menu items?
My menu:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/test1"
android:title="Test" />
<item android:id="#+id/test2"
android:title="Test 2" />
</menu>
How I open the popup menu:
PopupMenu popupMenu = new PopupMenu(getContext(), mButton);
popupMenu.getMenuInflater().inflate(R.menu.popup_menu, popupMenu.getMenu());
popupMenu.show();
Try this as part of your styles.xml file:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:popupMenuStyle">#style/PopupMenu</item>
<item name="android:textAppearanceLargePopupMenu">#style/myPopupMenuTextAppearanceLarge</item>
<item name="android:textAppearanceSmallPopupMenu">#style/myPopupMenuTextAppearanceSmall</item>
</style>
<style name="PopupMenu" parent="#android:style/Widget.PopupMenu">
<item name="android:popupBackground">#FFFFFF</item>
<item name="android:divider">#444444</item>
<item name="android:dividerHeight">1px</item>
<item name="android:background">#FFFFFF</item>
</style>
<style name="myPopupMenuTextAppearanceSmall" parent="#android:style/TextAppearance.DeviceDefault.Widget.PopupMenu.Small">
<item name="android:textColor">#000000</item>
<item name="android:textSize">12sp</item>
<item name="android:background">#FFFFFF</item>
</style>
<style name="myPopupMenuTextAppearanceLarge" parent="#android:style/TextAppearance.DeviceDefault.Widget.PopupMenu.Large">
<item name="android:textColor">#000000</item>
<item name="android:textSize">18sp</item>
<item name="android:background">#FFFFFF</item>
</style>
</resources>
and then in your xml layout file for the activity add this line:
style="#style/AppTheme"
or in your AndroidManifest.xml file, add this to the application tag:
android:theme="#style/AppTheme"
This will affect how Android renders a popup menu in your app.

Customize back button on ActionBar (Android)

in my app i added back button on ActionBar but this is not visible properly because of dark theme of ActionBar. both ActionBar and back Button are black in color so back button is not visible.
i added this code in values.xml file
<style name="Theme.MyFancyTheme" parent="android:Theme.Holo">
<item name="android:homeAsUpIndicator">#drawable/up</item>
</style>
and set.
minSdkVersion="14"
but it's not showing custom back buttom.
In the res/values/styles.xml file put some custom style:
<style name="AppThemeWithBackButton" parent="android:Theme.Holo.Light">
<item name="android:actionBarStyle">#style/ActionBar</item>
<item name="android:actionMenuTextColor">#color/white</item>
<item name="android:homeAsUpIndicator">#drawable/actionbar_back_button</item>
</style>
<style name="ActionBar" parent="android:Widget.ActionBar">
<item name="android:background">#drawable/actionbar_background</item>
<item name="android:displayOptions">useLogo|homeAsUp|showTitle</item>
<item name="android:titleTextStyle">#style/TitleText</item>
</style>
<style name="TitleText" parent="android:TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#color/white</item>
<item name="android:textAllCaps">false</item>
</style>
and use drawable/actionbar_back_button.xml layout:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:left="16dp"
android:right="16dp"
android:drawable="#drawable/back_icon" />
</layer-list>
and use drawable/actionbar_background.xml layout.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#color/action_bar_color" />
</shape>
Above all code is regarding of customizing actinobar button and background. You can modify it as you want. Hope it will help you. Enjoy!!!

Android ActionBarSherlock menu font color

I want to modify the menu item's font color in ActionBarSherlock. I try few solution: Action Bar menu item text color, How to style the menu items on an Android action bar and so on, but doesn't work for my app.
here is my style code:
<style name="onTime.ActionBar.Root" parent="Widget.Sherlock.ActionBar">
<item name="android:logo">#drawable/ic_actionbar</item>
<item name="android:titleTextStyle">#style/onTime.Title.Root</item>
</style>
<style name="onTime.Title.Root" parent="TextAppearance.Sherlock.Widget.ActionBar.Title">
<item name="android:textColor">#color/font_testing</item>
</style>
<style name="onTime.ActionBar.Default" parent="onTime.ActionBar.Root">
<item name="android:background">#color/action_bar_grey</item>
</style>
<style name="onTime.Theme.Default" parent="Theme.Sherlock.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/onTime.ActionBar.Default</item>
</style>
my menu xml (inflated in onCreateOptionsMenu() ):
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/menu_update"
android:orderInCategory="100"
android:showAsAction="always"
android:title="#string/menu_update" />
</menu>
How can I modify menu font's color?
Try
<style name="YOURTHEME.ActionBar.TitleTextStyle" parent="TextAppearance.Sherlock.Widget.ActionBar.Title">
<item name="android:textColor">#color/YOUR_COLOR</item>
<item name="textColor">#color/YOUR_COLOR</item>
<item name="android:textSize">#dimension/MEDIUM_TEXT</item>
<item name="textSize">#dimension/MEDIUM_TEXT</item>
</style>

How I make a logo and actionBar transparent?

I am using a .png for both my logo and action Bar menu items. I am using the android.Holo.light theme.
Even though I've made the background transparent for both the logo and the menu items, a grey shaded area is still showing behind the .png. How do I change this?
Take a look at my menu XML and my style override XML below.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="android:Theme.Holo.Light">
<item name="android:selectableItemBackground">#color/transparent</item>
<item name="android:background">#00000000</item>
</style>
<style name="ActionBar" parent="#android:style/Widget.Holo.Light.ActionBar" >
<item name="android:selectableItemBackground">#color/transparent</item>
<item name="android:background">#00000000</item>
</style>
<style name="textTitle"
parent="#android:style/TextAppearance">
<item name="android:textSize">20dp</item>
<item name="android:textColor">#DC0451</item>
<item name="android:textStyle">bold</item>
</style>
<style name="textDescription"
parent="#android:style/TextAppearance">
<item name="android:textSize">15dp</item>
<item name="android:textColor">#666666</item>
</style>
</resources>
Menu xml
<item
android:id="#+id/Category"
android:title="Category"
android:showAsAction="always|withText"
android:icon="#drawable/menuitemselect"
style="#style/ActionBar"
>
<menu>
<item
android:id="#+id/catalog"
android:title="Main Catalog"
android:icon="#drawable/menuitemselect"
android:onClick="catalogClick"
/>
<item android:id="#+id/newvideos"
android:title="New"
android:icon="#drawable/menuitemselect"
android:onClick="newVideoClick"
style="#style/ActionBar"
/>
<item
android:id="#+id/popularvideos"
android:title="Popular"
android:icon="#drawable/menuitemselect"
android:onClick="popularVideoClick"
style="#style/ActionBar"
/>
</menu>
</item>
<item android:id="#+id/backButton"
android:title="Back"
android:showAsAction="ifRoom"
android:icon="#drawable/ic_launcher"
/>
</menu>
Thank you
I found that the issue was with :
<item name="android:selectableItemBackground">#color/transparent</item>.
I added it in an attempt to get rid of default highlight feature. It seems when I have this set, the grey background shows up. When I remove it, it acts as it should.

Categories

Resources