How to change ActionBar menu background color (android 4 & 5)
Background Color of menu / drop down / spinner
One of a few options:
Edit styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:popupMenuStyle">@style/PopupMenu</item>
<item name="android:popupBackground">#272727</item>
<item name="android:itemBackground">#cc9d3e</item>
</style>
Create popup_menu.xml
under res/menu/ like this:
<?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"
android:layout_width="32dp"
android:tint="@color/timeSettings"
app:popupTheme="@style/PopupMenu">
<item
android:id="@+id/min0"
android:orderInCategory="100"
android:title="0"
app:showAsAction="never" />
</menu>
Edit popupMenu in your java-file
:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_clock);
//Time
secBtn = (Button) findViewById(R.id.btn_sec);
secBtn.setText("00");
//levelBtn.setTypeface(tf1);
secBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PopupMenu popupMenu = new PopupMenu(MainActivityClock.this, secBtn);
popupMenu.getMenuInflater().inflate(R.menu.popup_menu_sec, popupMenu.getMenu());
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
//Toast.makeText(MainActivity.this, "" + item.getTitle(), Toast.LENGTH_SHORT).show();
secBtn.setText("" + item.getTitle());
workTime_sec = Integer.parseInt(item.getTitle().toString());
//sec = item.getTitle().toString();
System.out.println("workTime_sec: " + workTime_sec);
return true;
}
});
popupMenu.show();
}
});
}
You can simply add the line like this:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- To change the background of options menu-->
<item name="android:itemBackground">*Your_color*</item>
</style>
add actionOverflowMenuStyle item to your app theme
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="actionOverflowMenuStyle">@style/CMOptionsMenu</item>
</style>
<style name="CMOptionsMenu" parent="Widget.AppCompat.PopupMenu.Overflow">
<item name="android:popupBackground">your color code</item>
</style>