Change the style of the Android context menu edittext

I want to change the context menu context of the EditText context menu when you click EditText for a long time.

I tried the following code but it does not work. The background of the context menu is still unchanged.

 <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="dialogTheme">@style/MyDialogTheme</item> <item name="popupMenuStyle">@style/MyPopupStyle</item> </style> <style name="MyPopupStyle" parent="Widget.AppCompat.PopupMenu"> <item name="android:popupBackground">@color/colorAccent</item> </style> <style name="MyDialogTheme" parent="Base.V7.Theme.AppCompat.Dialog"> <item name="android:colorBackground">@color/colorAccent</item> </style> 

As a result, I want the context menu of the context menu to be the same as the accent color, which is magenta. How can i achieve this?

enter image description here

+6
source share
1 answer

Code result My theme:

 <style name="PopupMenu" parent="@style/Widget.AppCompat.Light.PopupMenu"> <item name="android:popupBackground">@color/popup_background</item> </style> <style name="Base.Theme.DesignDemo" parent="Theme.AppCompat.DayNight.NoActionBar"> <item name="colorPrimary">#673AB7</item> <item name="android:popupMenuStyle">@style/PopupMenu</item> <item name="colorPrimaryDark">#512DA8</item> <item name="colorAccent">#FF4081</item> <item name="android:windowBackground">@color/window_background</item> <item name="android:popupBackground">@color/popup_background</item> <item name="android:itemBackground">@color/popup_background</item> **<item name="android:actionModeBackground">@color/popup_background</item>** </style> <resources> <color name="window_background">#FFF5F5F5</color> <color name="popup_background">#FF4081</color> </resources> 

Using pop-up context menu:

 @Override public boolean onLongClick(View v) { PopupMenu menu = new PopupMenu(this, v); MenuInflater inflater = menu.getMenuInflater(); inflater.inflate(R.menu.drawer_view, menu.getMenu()); menu.show(); return false; } 

enter image description here

Is it possible if you can share your code for a popup?

0
source

All Articles