java - 在 Custom BottomSheetDialog Android 中添加菜单

标签 java android modal-dialog android-bottomsheetdialog bottomsheetdialogfragment

The is what i want to have
我有一个 BottomSheetDialog,并且我已经在它上面夸大了我的自定义布局。但是当我尝试将菜单添加到它时。它没有出现。
如上图所示,Discord 与出现在角落的菜单具有相同的功能。我该怎么做。请帮帮我。
这是我的代码

//This is my ViewProfile BottomSheetDialog

public class ViewProfileFragment extends BottomSheetDialogFragment {

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        CreateView = inflater.inflate(R.layout.fragment_view_profile, container, true);

        return CreateView;

    }

@Override
    public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
        super.onCreateOptionsMenu(menu, inflater);
        inflater.inflate(R.menu.view_profile_menu, menu);
    }

}

最佳答案

我认为这是不可能的,选项菜单也不是为此而设计的。这是来自 documentation on menus :

"The options menu is the primary collection of menu items for an activity. It's where you should place actions that have a global impact on the app, such as "Search," "Compose email," and "Settings."


我认为 PopUpMenu在这里会更合适:

"Rather, the popup menu is for extended actions that relate to regions of content in your activity."

关于java - 在 Custom BottomSheetDialog Android 中添加菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67740604/

相关文章:

java - 如何获取Firebase用户数据

android - ListView/ExpandableListView setEmptyView() 无效

javascript - Twitter Bootstrap 2.0.4 Modal - 如何将模式淡入淡出效果应用于新创建的模式类样式?

IE 中 <object> 上的 jQuery 单击监听器失败

java - 泛型对象创建在 Eclipse 中显示错误,但在 Maven 中编译

java - 同步块(synchronized block)的绝对等价物?

java - 如何在同一个二维数组中使用两个构造函数? java

Android API 14, 15 TextView 省略整个字

java - 从 Activity 上下文外部调用 startActivity() 需要 FLAG_ACTIVITY_NEW_TASK 标志。这真的是你想要的吗?

javascript - 带有包含表单的 Bootstrap 模态视图的 Rails 应用程序,提交和消失模态视图而无需重新加载页面