how to change option menu background color - android

I am trying to change option menu background , but there is white space top and bottom
my toolbar style
app:popupTheme="#style/ThemeOverlay.MyTheme"
<style name="ThemeOverlay.MyTheme" parent="ThemeOverlay.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<!-- To change the popup menu and app text color -->
<item name="android:textColor">#color/white</item>
<!-- To change the background of options menu-->
<item name="android:itemBackground">#color/black</item>
</style>
Example:

Are you searching for this?
Create style for menu in your app style and add that entry in theme of your app
don't forgot to add that theme in you menifest's Application tag
android:theme="#style/AppTheme"

There problem with the material theme
<style name="Theme.MyApplication" parent="Theme.AppCompat.DayNight.DarkActionBar">
<item name="android:itemBackground">#color/bluish_green</item>
</style>
<style name="ThemeOverlay.MyTheme" parent="Theme.MyApplication">
<!-- To change the popup menu and app text color -->
<item name="android:textColor">#color/white</item>
<!-- To change the background of options menu-->
<item name="android:itemBackground">#color/black</item>
<item name="android:popupBackground">#color/black</item>
<item name="android:drawablePadding">0dp</item>
<item name="android:dividerHeight">1dp</item>
</style>

Related

How to change the background color of Action Bar's Option Menu in Android 5.1 & 6.0?

I'd like to change the background color of the option (overflow) menu in Android above 5.0. I have tried all the methods but it is still showing the default color set by the theme. I used the following code & XML configs.
There is an easy way to change the colors in Actionbar Use ActionBar Generator and copy paste all file in your res folder and change your theme in Android.manifest file.
Other way is to modify your styles.xml like this-
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- This is the styling for action bar -->
<item name="actionBarStyle">#style/MyActionBar</item>
<!--To change the text styling of options menu items</item>-->
<item name="android:itemTextAppearance">#style/MyActionBar.MenuTextStyle</item>
<!--To change the background of options menu-->
<item name="android:itemBackground">#color/skyBlue</item>
</style>
<style name="MyActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="background">#color/red</item>
<item name="titleTextStyle">#style/MyActionBarTitle</item>
</style>
<style name="MyActionBarTitle" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/white</item>
</style>
<style name="MyActionBar.MenuTextStyle"
parent="style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/red</item>
<item name="android:textStyle">bold</item>
<item name="android:textSize">25sp</item>
</style>
and this is how it looks--MenuItem background color is skyblue and MenuItem text color is pink with textsize as 25sp:--
This answer is taken from here.

Having trouble changing the ActionMode background color in Android

My ActionMode menu is showing up as plain white and I don't know why.
I have an ActionMode menu.xml which simply has a delete option:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/action_delete"
android:title="Delete"
android:icon="#android:drawable/ic_menu_delete"/>
</menu>
and I have a theme applied to my whole app, defined in styles.xml:
<resources>
<!-- Base application theme -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/paletteLightBlue3</item>
<item name="colorPrimaryDark">#color/dark_grey</item>
<item name="colorAccent">#color/paletteLightBlue</item>
<item name="android:actionModeStyle">#style/aModeBg</item>
</style>
<style name="aModeBg" parent="#style/Widget.AppCompat.ActionMode">
<item name="android:actionModeBackground">#color/dark_red</item>
</style>
</resources>
As you can see, I've tried setting the actionModeBackground property to dark red, but it still just shows up as white. Can anyone help? Thanks.
OK so I solved this by simply doing this:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/paletteLightBlue3</item>
<item name="colorPrimaryDark">#color/dark_grey</item>
<item name="colorAccent">#color/paletteLightBlue</item>
<item name="android:actionModeBackground">#color/dark_red</item>
</style>
I just put set the actionModeBackground in my AppTheme, instead of a separate style. Simple.

Changing the colour of actionbar hides the settings button

I tried to change the colour of actionbar by making few changes in default theme.
But the problem is when the colour changes, it hides the settings button.please suggest me the changes.
Heres the xml file for styles.xml:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorWhite</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:windowActionBarOverlay">true</item>
</style>
You can add the android:textColorSecondary attribute to your theme.
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
.....
<!-- color of the menu overflow icon -->
<item name="android:textColorSecondary">#color/my_color</item>
</style>
Otherwise, since you are using a white Toolbar, you can use override the theme with:
<android.support.v7.widget.Toolbar
app:theme="#style/ThemeToolbar" />
with:
<style name="ThemeToolbar" parent="Theme.AppCompat.Light">
<!-- navigation icon color -->
<item name="colorControlNormal">#color/my_color</item>
<!-- color of the menu overflow icon -->
<item name="android:textColorSecondary">#color/my_color</item>
</style>

Font bold in action bar title

After several hours of try I give up... How to set bold font for action bar title? I have values/styles.xml below:
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Background color -->
<item name="android:background">#f1a30b</item>
<!-- Menu text -->
<item name="android:textColor">#ffffff</item>
<item name="android:textStyle">bold|italic</item>
<!-- Ttle color -->
<item name="android:textColorPrimary">#ffffff</item>
<item name="android:titleTextStyle">#style/AppTheme.MyActionBar.TitleTextStyle</item>
</style>
<style name="AppTheme.MyActionBar.TitleTextStyle" parent="ThemeOverlay.AppCompat.ActionBar">
<item name="android:background">#81CFEB</item>
<item name="android:textColor">#000000</item>
<item name="android:textStyle">bold</item>
</style>
</resources>
Menu text color, style and background color OK. But how to change font for title (style and text size)? I need bold and 25dp.
I understand that in manifest I should only have line android:theme="#style/AppTheme" for application... nothing more. Should I import some class in activity?
You need to make override some properties for Theme which is explained Here.

Style is ignored and everything is gray in Lollipop

I am trying to change the style of the app but everything is grey instead. What's the problem?
I am using android studio. This project was originally on eclipse. I am not building it using Lollipop on Android Studio
<application
android:name=".MainApplication"
tools:replace="android:icon,android:theme"
android:label="#string/app_name"
android:logo="#drawable/ic_logo"
android:theme="#style/Theme.Materialred" >
styles_materialred.xml:
<resources>
<style name="Theme.Materialred" parent="#style/Theme.AppCompat.Light">
<item name="actionBarItemBackground">#drawable/selectable_background_materialred</item>
<item name="popupMenuStyle">#style/PopupMenu.Materialred</item>
<item name="dropDownListViewStyle">#style/DropDownListView.Materialred</item>
<item name="actionBarTabStyle">#style/ActionBarTabStyle.Materialred</item>
<item name="actionDropDownStyle">#style/DropDownNav.Materialred</item>
<item name="actionBarStyle">#style/ActionBar.Solid.Materialred</item>
<item name="actionModeBackground">#drawable/cab_background_top_materialred</item>
<item name="actionModeSplitBackground">#drawable/cab_background_bottom_materialred</item>
<item name="actionModeCloseButtonStyle">#style/ActionButton.CloseMode.Materialred</item>
</style>
<style name="ActionBar.Solid.Materialred" parent="#style/Widget.AppCompat.Light.ActionBar.Solid">
<item name="background">#drawable/ab_solid_materialred</item>
<item name="backgroundStacked">#drawable/ab_stacked_solid_materialred</item>
<item name="backgroundSplit">#drawable/ab_bottom_solid_materialred</item>
<item name="progressBarStyle">#style/ProgressBar.Materialred</item>
</style>
<style name="ActionBar.Transparent.Materialred" parent="#style/Widget.AppCompat.Light.ActionBar">
<item name="background">#drawable/ab_transparent_materialred</item>
<item name="progressBarStyle">#style/ProgressBar.Materialred</item>
</style>
<style name="PopupMenu.Materialred" parent="#style/Widget.AppCompat.Light.PopupMenu">
<item name="android:popupBackground">#drawable/menu_dropdown_panel_materialred</item>
</style>
<style name="DropDownListView.Materialred" parent="#style/Widget.AppCompat.Light.ListView.DropDown">
<item name="android:listSelector">#drawable/selectable_background_materialred</item>
</style>
<style name="ActionBarTabStyle.Materialred" parent="#style/Widget.AppCompat.Light.ActionBar.TabView">
<item name="android:background">#drawable/tab_indicator_ab_materialred</item>
</style>
<style name="DropDownNav.Materialred" parent="#style/Widget.AppCompat.Light.Spinner.DropDown.ActionBar">
<item name="android:background">#drawable/spinner_background_ab_materialred</item>
<item name="android:popupBackground">#drawable/menu_dropdown_panel_materialred</item>
<item name="android:dropDownSelector">#drawable/selectable_background_materialred</item>
</style>
<style name="ProgressBar.Materialred" parent="#style/Widget.AppCompat.ProgressBar.Horizontal">
<item name="android:progressDrawable">#drawable/progress_horizontal_materialred</item>
</style>
<style name="ActionButton.CloseMode.Materialred" parent="#style/Widget.AppCompat.Light.ActionButton.CloseMode">
<item name="android:background">#drawable/btn_cab_done_materialred</item>
</style>
<!-- this style is only referenced in a Light.DarkActionBar based theme -->
<style name="Theme.Materialred.Widget" parent="#style/Theme.AppCompat">
<item name="popupMenuStyle">#style/PopupMenu.Materialred</item>
<item name="dropDownListViewStyle">#style/DropDownListView.Materialred</item>
</style>
Set the color in this way in action bar theme.
<item name="colorPrimary">#color/primaryDef</item>
Read this interesting article of Chris Banes https://chris.banes.me/2014/10/17/appcompat-v21/#migrationfromprevioussetup
I was having this problem and just noticed that there was a separate styles.xml file for Lollipop. It was originally hidden by the default file, but clicking the arrow reveals it. Editing this one works as expected.
You have to use this:
<style name="AppThemeRandom" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<!-- The primary branding color for the app. By default, this is the color applied to the
action bar background. -->
<item name="colorPrimary">#color/md_indigo_500</item>
<!-- Dark variant of the primary branding color. By default, this is the color applied to
the status bar (via statusBarColor) and navigation bar (via navigationBarColor). -->
<item name="colorPrimaryDark">#color/md_indigo_700</item>
<!-- Bright complement to the primary branding color. By default, this is the color applied
to framework controls (via colorControlActivated). -->
<item name="colorAccent">#color/md_pink_A200</item>
<!-- The color applied to framework controls in their normal state. -->
<item name="colorControlNormal">#color/md_amber_500</item>
<!-- The color applied to framework controls in their activated (ex. checked) state. -->
<item name="colorControlActivated">#color/md_green_500</item>
<!-- The color applied to framework control highlights (ex. ripples, list selectors). -->
<item name="colorControlHighlight">#color/md_teal_500</item>
<!-- The color applied to framework buttons in their normal state. -->
<item name="colorButtonNormal">#color/md_red_500</item>
<!-- The color applied to framework switch thumbs in their normal state. -->
<item name="colorSwitchThumbNormal">#color/md_black_1000_50</item>
<!-- Inactive track color(75% transparency) -->
<item name="android:colorForeground">#color/md_black_1000_75</item>
</style>
Obviously, choose your colors, it is a random theme to check all colors in status bar, toolbar, widgets like checkbox, etc.

Categories

Resources