底部导航覆盖了我的抽屉

时间:2016-05-23 14:04:59

标签: java android

我正在尝试使用抽屉和底部导航编写Android应用程序。由于仍然没有官方图书馆我遵循tutorial

现在我有一个底部导航,但它在我使用时覆盖了抽屉。 Roughike,本教程的创建者,试图解决问题,我引用:

  

“你需要做的就是不要将BottomBar连接到你的身上   活动,将其附加到包含您的内容的视图“。

但是通过这样做,我再也看不到应该在我的活动中看到的片段了。

如何修复此错误?

我试着给你一些代码来给你一个想法。

private BottomBar mBottomBar;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setDrawerCurrent(R.id.nav_cerca);
    FragmentManager fragmentManager = getSupportFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    FragmentCerca fragment = new FragmentCerca();
    fragmentTransaction.add(getViewContentId(), fragment);
    fragmentTransaction.commit();

    mBottomBar = BottomBar.attach(getViewContent(), savedInstanceState);
    mBottomBar.setItemsFromMenu(R.menu.bottombar_menu, new OnMenuTabClickListener() {
        @Override
        public void onMenuTabSelected(@IdRes int menuItemId) {
            if (menuItemId == R.id.bottomBarItemOne) {
                // The user selected item number one.
            }
        }

        @Override
        public void onMenuTabReSelected(@IdRes int menuItemId) {
            if (menuItemId == R.id.bottomBarItemOne) {
                // The user reselected item number one, scroll your content to top.
            }
        }
    });


    mBottomBar.mapColorForTab(0, ContextCompat.getColor(this, R.color.colorPrimary));
    mBottomBar.mapColorForTab(1, ContextCompat.getColor(this, R.color.colorPrimary));
    mBottomBar.mapColorForTab(2, ContextCompat.getColor(this, R.color.colorPrimary));
    mBottomBar.mapColorForTab(3, ContextCompat.getColor(this, R.color.colorPrimary));
    mBottomBar.mapColorForTab(4, ContextCompat.getColor(this, R.color.colorPrimary));

}

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);

    // Necessary to restore the BottomBar's state, otherwise we would
    // lose the current tab on orientation change.
    mBottomBar.onSaveInstanceState(outState);
}

注意:getViewContent()是管理视图并传递当前视图的父类的方法。

0 个答案:

没有答案