在同一应用中使用抽屉添加底部导航视图时出现问题

时间:2018-06-26 04:52:15

标签: navigation-drawer bottomnavigationview

我进行了很多搜索,并尝试在同一应用程序中使用Drawer添加BottomNavigationView。但这会导致崩溃并显示错误

    Unable to start activity 
    ComponentInfo{com.zinedroid.android.atmadharshan/
    com.zinedroid.android.atmadharshan.Activity.HomeActivity}: 
    android.view.InflateException: Binary XML file line #33: Error inflating 
    class android.support.design.widget.BottomNavigationView

activity_home.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">

<include
    layout="@layout/app_bar_home"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

   <android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:layout_marginTop="?attr/actionBarSize"
    android:background="@color/white"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/nav_header_home"
    app:itemIconTint="@color/black"
    app:itemTextColor="@color/black"
    app:menu="@menu/activity_home_drawer">
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>

在app_bar_home中添加了ottomNavigationView

app_bar_home.xml

   <android.support.design.widget.BottomNavigationView
    android:id="@+id/navigation"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:background="?android:attr/windowBackground"
    app:menu="@menu/navigation" />
 </android.support.design.widget.CoordinatorLayout>

HomeActivity.class

   BottomNavigationView bottomNavigationView = (BottomNavigationView)
            findViewById(R.id.navigation);

    bottomNavigationView.setOnNavigationItemSelectedListener(
            new BottomNavigationView.OnNavigationItemSelectedListener() {
                @Override
                public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                    switch (item.getItemId()) {
                        case R.id.navigation_home:

                        case R.id.navigation_dashboard:

                        case R.id.navigation_notifications:

                    }
                    return true;
                }
            });

//导航代码

任何人都可以帮助我做到这一点吗?

0 个答案:

没有答案