在自定义 BottomSheetDialog 中添加菜单 Android
Adding a menu in Custom BottomSheetDialog Android
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."
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."