簡體   English   中英

Android片段中的導航抽屜

[英]Navigation drawer in android fragment

我在單獨的類中創建了導航抽屜,並將該活動擴展為一個片段。 導航抽屜在該片段中工作正常。 我正在使用FragmentManager切換片段的內容。

FragmentManager fragmentManager = getSupportFragmentManager();

    if (savedInstanceState != null) {
        if (savedInstanceState.containsKey("content")) {
            String content = savedInstanceState.getString("content");
            if (content.equals(FavoriteListFragment.ARG_ITEM_ID)) {
                if (fragmentManager.findFragmentByTag(FavoriteListFragment.ARG_ITEM_ID) != null) {
                    setFragmentTitle(R.string.favorites);
                    contentFragment = fragmentManager
                            .findFragmentByTag(FavoriteListFragment.ARG_ITEM_ID);
                }
            }
        }
        if (fragmentManager.findFragmentByTag(ProductListFragment.ARG_ITEM_ID) != null) {
            pdtListFragment = (ProductListFragment) fragmentManager
                    .findFragmentByTag(ProductListFragment.ARG_ITEM_ID);
            contentFragment = pdtListFragment;
        }
    } else {
        pdtListFragment = new ProductListFragment();
        setFragmentTitle(R.string.app_name);
        switchContent(pdtListFragment, ProductListFragment.ARG_ITEM_ID);
    }

導航抽屜在ProductListFragment中可見,但是在單擊FavoriteListFragment時,該抽屜就會被該片段覆蓋。 如何解決? 我需要同時在ProductListFragment和FavoriteListFragment中獲得抽屜

我建議您使用Mike Penz的 MaterialDrawer庫。 簡單而強大的API。 只需瀏覽示例以檢查lib。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM