我正在尝试在显示全屏对话框时显示其他菜单,但该菜单不会出现。而是显示一个空白菜单。
我尝试从原始活动中有条件地调用它,并且尝试从对话框视图中调用它。
这是全屏对话框视图:
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="0dp" <-- changed this to "match_parrent"
android:layout_height="0dp"
android:layout_marginBottom="45dp"
android:background="@android:color/transparent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHeight_default="wrap"
app:layout_constraintHeight_max="360dp"
app:layout_constraintHeight_min="60dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/header"/>
菜单XML :
public class MyMainView extends DialogFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NORMAL, R.layout.layout_full_screen_dialog);
setHasOptionsMenu(true);
}
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
menu.clear();
new MenuInflater(this.getActivity()).inflate(R.menu.add_to_user_library, menu);
//inflater.inflate(R.menu.add_to_user_library, menu);
super.onCreateOptionsMenu(menu, inflater);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View view = inflater.inflate(R.layout.add_to_user_library, container, false);
// view code here
return view;
}
}
从活动
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".result.ResultActivity">
<item
android:id="@+id/save"
android:icon="@drawable/ic_check"
android:showAsAction="ifRoom"
android:title="@string/menu_save_library"
tools:ignore="AppCompatResource" />
<item
android:id="@+id/go_back"
android:icon="@drawable/ic_clear"
android:showAsAction="ifRoom"
android:title="@string/menu_save_library"
tools:ignore="AppCompatResource" />
</menu>
现在,当对话框出现但菜单在加载之前就出现了,然后变为空白。
我看到的是以下内容。