Java 底部的导航盖上了我的抽屉
我正在尝试为Android编写一个带有抽屉和底部导航的应用程序。因为现在还没有正式的图书馆,我就这样做了 现在我有一个底部导航,但当我使用它时,它会覆盖抽屉。本教程的创建者拉夫维克试图给出问题的解决方案,我引用: “你所需要做的就是不要把底部的横杆系在你的腿上 活动,将其附加到包含您的内容的视图” 但是通过这样做,我再也看不到应该在我的活动中可见的片段了 如何修复此错误 我试着给你一些代码来给你一个想法Java 底部的导航盖上了我的抽屉,java,android,Java,Android,我正在尝试为Android编写一个带有抽屉和底部导航的应用程序。因为现在还没有正式的图书馆,我就这样做了 现在我有一个底部导航,但当我使用它时,它会覆盖抽屉。本教程的创建者拉夫维克试图给出问题的解决方案,我引用: “你所需要做的就是不要把底部的横杆系在你的腿上 活动,将其附加到包含您的内容的视图” 但是通过这样做,我再也看不到应该在我的活动中可见的片段了 如何修复此错误 我试着给你一些代码来给你一个想法 private BottomBar mBottomBar; @Override prote
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()
是一个父类的方法,它管理视图并传递当前视图。attach
的文档说:“将底部栏绑定到指定视图的父视图”看起来您需要将其附加到Fragment.getView()
或类似文件。检查该方法的来源。@TWiStErRob我试着按照你说的做,但这样应用程序崩溃了……你是否尝试将底部栏附加到onActivityCreated()
中的Fragment.getView()
?