简体   繁体   English

在自定义 BottomSheetDialog Android 中添加菜单

[英]Adding a menu in Custom BottomSheetDialog Android

The is what i want to have这就是我想要的

I have a BottomSheetDialog and i have inflated my custom layout on it.我有一个 BottomSheetDialog,并且我已经在它上面夸大了我的自定义布局。 But when i try to add the menu to it.但是当我尝试将菜单添加到它时。 It doesn't appear.它没有出现。

Discord has the same thing with the menu appearing in the corner as you can see in the image above. Discord 具有相同的功能,菜单出现在角落,如上图所示。 How am i supposed to do it.我该怎么做。 Please help me out.请帮帮我。

Here is my code这是我的代码

//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);
    }

}

I don't think this is possible, nor is the Options Menu meant for this.我认为这是不可能的,选项菜单也不是为此而设计的。 This is from the 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." “选项菜单是活动菜单项的主要集合。您应该在其中放置对应用程序具有全局影响的操作,例如“搜索”、“撰写 email”和“设置”。

I think the PopUpMenu would be more appropriate here:我认为PopUpMenu在这里更合适:

"Rather, the popup menu is for extended actions that relate to regions of content in your activity." “相反,弹出菜单用于与活动中的内容区域相关的扩展操作。”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM