For background changes when selecting PopupMenu, apply "listselector_popup.xml" to the style
I want to make it happen.
As it is, "@color/dialog_background_color
Only ' ' applies, but 'listselector_popup.xml' does not apply when selected.
*The background color is gray, which is close to black, but when selected, it is light gray on Android 4.4.4 and black on Android 8.
I don't feel any change when I use Android 8, so I want to specify it myself.
Even if the source is corrected by referring to the answer below, there is no change.
Android:background color when menu item is pressed
styles.xml
<!--Pop-up Theme-->
<style name="PopupMenu" parent="@android:style/Widget.PopupMenu">
<item name="android:textColor">@color/font_color</item>
<item name="android:colorBackground">@color/dialog_background_color</item>
<item name="android:dropDownSelector">@drawable/listselector_popup</item>
<item name="android:listViewStyle">@style/CustomListView2</item>
</style>
<style name="CustomListView2" parent="@android:style/Widget.ListView">
<item name="android:listSelector">@drawable/listselector_popup</item>
</style>
listselector_popup.xml
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:state_enabled="false" android:state_pressed="true" android:drawable="@color/listselect_dialog_color"/>
<item android:state_focused="true" android:state_enabled="false" android:drawable="@color/listselect_dialog_color"/>
<item android:state_focused="true" android:state_pressed="true" android:drawable="@color/listselect_dialog_color"/>
<item android:state_focused="false" android:state_pressed="true" android:drawable="@color/listselect_dialog_color"/>
<item android:state_focused="true" android:drawable="@color/listselect_dialog_color"/>
</selector>
//java
// PopupMenu Style Settings
Context wrapper = new ContextThemeWrapper (context, R.style.PopupMenu);
// Creating an Instance of PopupMenu
PopupMenu popup=new PopupMenu(wrapper,v);
We were able to:
PopupMenu is defined in item, and it's itemBackground.
styles.xml
<!--Pop-up Theme-->
<style name="PopupMenu" parent="@android:style/Widget.PopupMenu">
<item name="android:textColor">@color/font_color</item>
<item name="android:colorBackground">@color/dialog_background_color</item>
<item name="android:itemBackground">@drawable/listselector_popup</item>
</style>
© 2024 OneMinuteCode. All rights reserved.