내 액티비티에 조각이 있고 조각에 자체 도구 모음이 있습니다. 이처럼 :조각 도구 모음에서 메뉴 항목을 설정하는 방법은 무엇입니까?
<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>
나는 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);
}
하지만 MainActivity의 tolbar에 메뉴를 추가했다. Setup_next_toolbar
에 menuItem을 어떻게 설정할 수 있습니까?
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
//TODO Add your menu entries here
inflater.inflate(R.menu.menu, menu);
super.onCreateOptionsMenu(menu, inflater);
}
내부
. http://stackoverflow.com/a/34082236/5722385 – Mrinmoy