我的Activity中有一个片段,片段有自己的工具栏.像这样:
这是片段的布局:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.hometsolutions.space.Fragments.ControlFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/Setup_next_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view_setup_next"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintTop_toBottomOf="@+id/setup_next_recycler" />
</LinearLayout>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
我想在Setup_next_toolbar上添加菜单.不在MainActivity工具栏上.
我在片段上做了这个:
在onCreate:setHasOptionsMenu(true);
然后
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.Setup_next_menu, menu);
}
Run Code Online (Sandbox Code Playgroud)
但它在MainActivity tolbar上添加了菜单.如何设置menuItems Setup_next_toolbar?