Width and height of the options menu?

Is there a way to get the width and height of the Options Menu in DPI (or any other dimension)?

+6
source share
3 answers

As I understand it - NO.

When you open the options menu, a new Window created - specifically to display the menu. And from activity (and this window) there is no way to get some information about other windows.

To control the layout, you can try to find the layout of the menu window and check how much dp it is (all standard Android layouts are in the sdk_folder / platform / platform-x / data / res / layout folder) But this is not the best way - it will be platform dependent, and if, for example, HTC has its own options menu, you will have problems.

+3
source

The Android menu object extends the view class; do the getHeight () en getWidth () methods not work?

If they work, but 0 is returned every time, look at this question, where does someone encounter this problem when they want to get the width and height of the view.

+1
source

Here in the answer you can find a class that can be expanded to a menu. And it will have usually controlled and read width and height.

+1
source

Source: https://habr.com/ru/post/905754/


All Articles