【问题标题】:BottomNavigationView with activities带有活动的底部导航视图
【发布时间】:2017-09-25 21:26:19
【问题描述】:

我正在使用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>

如何使此导航在所有活动上可见并在项目上设置 Click Listeners?我的导航中有五个项目,我想在单击项目 1 时显示例如活动 1,依此类推。

【问题讨论】:

    标签: android android-navigation bottomnavigationview


    【解决方案1】:

    我建议使用 Fragments 在选项卡之间切换。使用 Fragments 时很少有专家:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-12-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多