android - 如何使我的菜单显示在操作栏区域下方

标签 android android-layout android-activity

我的问题是如何将我的菜单下拉菜单移动到粉红色区域的空间(见第二张图片)。就好像现在它也出现在我不想要的操作栏区域中一样。我希望我的菜单是出现在操作栏的正下方。

请大家帮我解决这个问题。

enter image description here

菜单是这样来的。

enter image description here

我希望我的菜单显示在操作栏的正下方。

这就是我的 menu.xml 的样子

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context="com.example.mobileinventorysuit.MainActivity" >

    <item
        android:id="@+id/login_mnu_imports"
        android:icon="@drawable/import_menu"
        app:showAsAction="always"
        style="@style/OverflowMenu"
        android:title="Import"/> 
   <item
        android:id="@+id/login_mnu_settings"
        android:icon="@drawable/settings_menu"
        style="@style/OverflowMenu"
        app:showAsAction="always"
        android:title="Settings"/>
     <item
        android:id="@+id/login_mnu_dev"
        android:icon="@drawable/dev"
        style="@style/OverflowMenu"
        app:showAsAction="always"
        android:title="Device Info"/>
    <item
        android:id="@+id/login_mnu_exit"
        style="@style/OverflowMenu"
        app:showAsAction="always"
        android:icon="@drawable/ic_lock_power_off"
        android:title="Exit"/>


</menu>

最佳答案

实际上,ActionBar 菜单应该显示在操作栏的顶部。 来自Documentation

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

如果你仍然想要那种行为,你可以使用它。但不推荐。

<style name="OverflowMenu" parent="Widget.AppCompat.PopupMenu.Overflow" >
         <item name="overlapAnchor">false</item>
         <item name="dropDownVerticalOffset">?attr/actionBarSize</item>
</style>

检查这个答案 Why is my overflow dropdown menu on top of the actionbar?

编辑

如果你想把图标放在你的 ToolBar

menu.xml 中添加这个

 xmlns:app="http://schemas.android.com/apk/res-auto"

并将这一行添加到您的菜单项中

 app:showAsAction="always"

关于android - 如何使我的菜单显示在操作栏区域下方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32175932/

相关文章:

android - onActivityResult 后键盘隐藏

Android - 进程已死亡问题

java - 如何在 Android Studio 上向我的项目添加库?

android - 模拟器中的人脸检测 android + 网络摄像头预览

android - 查找某个回调的非常基本的术语

Android listView 找到滚动的像素数量

Android 自定义选项卡内容

android - 我们如何知道 Activity 共享元素转换将要运行?

java - 无法完成 Activity

android - 如何检测用户何时在其 Android 设备上按下 "menu"键?