Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/225.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 带活动的BottomNavigationView_Android_Android Navigation_Bottomnavigationview - Fatal编程技术网

Android 带活动的BottomNavigationView

Android 带活动的BottomNavigationView,android,android-navigation,bottomnavigationview,Android,Android Navigation,Bottomnavigationview,我正在使用BottomNavigationViewEx(具有非常好的特性的BottomNavigationView)。我有了布局,现在我想将这个导航与我的活动“连接”。通常是通过片段连接,但我的所有活动都扩展了AppCompatActivity 这是我的nav.xml <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://

我正在使用BottomNavigationViewEx(具有非常好的特性的BottomNavigationView)。我有了布局,现在我想将这个导航与我的活动“连接”。通常是通过片段连接,但我的所有活动都扩展了AppCompatActivity

这是我的nav.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ui.activity.RecipesActivity">

    <FrameLayout
        android:id="@+id/fragment_container"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toTopOf="@+id/navigation_view"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"/>

    <com.ittianyu.bottomnavigationviewex.BottomNavigationViewEx
        android:id="@+id/navigation_view"
        android:layout_width="0dp"
        android:layout_height="65dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        android:background="@color/colorPrimary"
        app:itemIconTint="@color/draw_item"
        app:itemTextColor="@color/draw_item"
        app:menu="@menu/nav_items" />

</android.support.constraint.ConstraintLayout>


如何使此导航在所有活动和项目上的设置单击侦听器上可见?我的导航栏上有五个项目,我想在单击项目1时显示活动1,以此类推。

我建议使用片段在选项卡之间切换。使用片段时的一些优点:

  • 它将防止破坏和创建活动和屏幕闪烁
  • 只持有一个BottomNavigationView更容易
  • 处理导航、保存和恢复状态的单一责任