How to Change the Background Color of Action Bar'S Option Menu in Android 4.2

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

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.

How to change Background color of menuItem in android?

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>

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

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:--

Sample Image

This answer is taken from here.

how to change option menu background color

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>

how can I change the background colour of my overflowmenu?

Add This style in your Style.xml And after set it in your ToolBar

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" >
<item name="android:textColorSecondary">@color/colorPrimary</item>
<item name="android:textColorPrimary">@android:color/white</item>
</style>

And in Activity

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" >

Change background color of the system settings menu above the actionbar

That area is called the status bar. Using the material theme, you can add this line to your styles xml to change the color.

<item name="android:colorPrimaryDark">@color/primary_dark</item>

Docs: https://developer.android.com/training/material/theme.html

To maintain compatibility, you should define your theme as such

<!-- extend one of the Theme.AppCompat themes -->
<style name="Theme.MyTheme" parent="Theme.AppCompat.Light">
<!-- customize the color palette -->
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@color/accent</item>
</style>

Then add this dependency in your build.gradle file

dependencies {
compile 'com.android.support:appcompat-v7:21.0.+'
}

Docs: https://developer.android.com/training/material/compatibility.html

NOTE: While this will allow older devices to use the Material theme, it cannot modify the status bar color. See this blog post

There are a couple workarounds that people have come up with here



Related Topics



Leave a reply



Submit