Why is my overflow dropdown menu on top of the actionbar?

匿名 (未验证) 提交于 2019-12-03 02:52:02

问题:

By default isn't it supposed to be under the actionbar? So what am I doing wrong?

@Override public boolean onCreateOptionsMenu(Menu menu) {     // Inflate the menu; this adds items to the action bar if it is present.     getMenuInflater().inflate(R.menu.main, menu);     return true; } 

res/menu/main.xml

回答1:

According to the Material Design specifications, the overflow menu should display on top of the action bar:

A menu is a temporary sheet of paper that always overlaps the app bar, rather than behaving as an extension of the app bar.

This is the default behavior for Android Lollipop applications as well as any applications that use the AppCompat v7 support library.



回答2:

This is default behaviour of AppCompat theme you are using. According to the Material Design guidelines, it is expected overflow menu to appear on top of it's anchor, the ActionBar.

You can force it to show below the action bar if by setting to your theme overlapAnchor to false

   


回答3:

Finally this works for me:

Source: https://stackoverflow.com/a/27134045/3586815

Thanks to Nikola Despotoski for the hint.



回答4:

This is the new default with Material Design. Popup menus will be displayed originating from the Button which opened them.

This is done to increase the visual connection between the Button and the popup menu. Just look at Googles apps which already use Material Design, there the popup menus act in the same way.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!