Java – Change the style of the context menu in Android

Change the style of the context menu in Android… here is a solution to the problem.

Change the style of the context menu in Android

In an Android activity, I feed an ImageView with only one menu item Added a context menu: “Close” (to hide the image).
However, the context menu doesn’t look very aesthetically pleasing when displayed, expanding into a large white rectangle that takes up almost the entire width of the screen. Is there a way to reduce the size of this rectangle to cover only the word “close”? This is my main question, but any pointers to how to change other styles of the context menu would be appreciated (e.g., background color or text font/color). Thanks!

Solution

I don’t think it’s possible to set the menu item width.

However, you can find great article here Shows how to customize the appearance of menu items.

Related Problems and Solutions