문제

i 내비게이션 서랍을 사용하여 응용 프로그램을 만들었고 "설정"메뉴를 표시 할 때 서랍을 엽니 다


내 컨테이너의 조각을 표시 할 때 두 개의 메뉴 "설정"과 "검색 정보"가 표시됩니다. http://saifulhq.wordpress.com/?attachment_id=242


그러나 머리글의 뒤로 버튼을 클릭 한 다음 서랍이 나타나면 그림 "설정", "설정", "검색 정보"와 같은 3 가지 항목
http://saifulhq.wordpress.com/?attachment_id=243


내 질문은 조각에서 메뉴 항목을 제거한 다음 서랍에서 메뉴 항목을 추가하는 방법입니다.


다음은 서랍의 코드가 메뉴 항목을 표시하는 코드

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    // If the drawer is open, show the global app actions in the action bar.
    // See also
    // showGlobalContextActionBar, which controls the top-left area of the
    // action bar.
    if (mDrawerLayout != null && isDrawerOpen()) {
        inflater.inflate(R.menu.global, menu);
        showGlobalContextActionBar();
    }
    super.onCreateOptionsMenu(menu, inflater);
}
.

이것은 showglobalcontextactionbar ()

/**
 * Per the navigation drawer design guidelines, updates the action bar to
 * show the global app 'context', rather than just what's in the current
 * screen.
 */
private void showGlobalContextActionBar() {
    ActionBar actionBar = getActionBar();
    actionBar.setDisplayShowTitleEnabled(true);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
    actionBar.setTitle(R.string.app_name);
}
.

도움이 되었습니까?

해결책

작업을 수행하는 작업을 위해 메뉴 작성을 onPrepaReOptionsMenu () oncreateoptionsmenu ()만이 한 번만 호출되기 때문에 메뉴가 생성 될 때마다 호출되는 방법입니다.

메뉴에서 메뉴 항목을 제거하려면 메뉴를 저장하고 removeItem ()

여기에 참조 http://developer.android.com/가이드 / 토픽 / ui / menus.html # changingthemenu

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top