Android 底部導航 用fragment的方式

//獲取到fragmentManager 
fragmentManager = getSupportFragmentManager();

//切換隱藏掉全部的Fragment
private void hideAllFragment() {
        for (int i = 0; i < fragmentArrayList.size(); i++) {
            fragmentManager.beginTransaction().hide(fragmentArrayList.get(i)).commit();
        }
    }
...
//當導航點擊的時候進行切換
                if (fragmentArrayList.get(position).isAdded()) {
                    hideAllFragment();
                    fragmentManager.beginTransaction().show(fragmentArrayList.get(position)).commit();
                } else {
                    hideAllFragment();
                    fragmentManager.beginTransaction().add(R.id.contentContainer, fragmentArrayList.get(position))
                            .show(fragmentArrayList.get(position))
                            .commit();
}
...
相關文章
相關標籤/搜索