If you want to set an arbitrary color, this seem to work rather well for androidx
. Tested on KitKat and Pie. Put this into your AppCompatActivity
:
@Override public View onCreateView(View parent, String name, Context context, AttributeSet attrs) {
if (name.equals("androidx.appcompat.view.menu.ListMenuItemView") &&
parent.getParent() instanceof FrameLayout) {
((View) parent.getParent()).setBackgroundColor(yourFancyColor);
}
return super.onCreateView(parent, name, context, attrs);
}
This sets the color of android.widget.PopupWindow$PopupBackgroundView
, which, as you might have guessed, draws the background color. There's no overdraw and you can use semi-transparent colors as well.