首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >安卓-用BottomNavigationView和FrameLayout实现BottomNavigationView

安卓-用BottomNavigationView和FrameLayout实现BottomNavigationView
EN

Stack Overflow用户
提问于 2020-06-29 10:55:22
回答 1查看 100关注 0票数 0

我目前正在创建一个应用程序,它有一个BottomNavigationView和一个片段的FrameLayout。我也想实现一个DrawerLayout或汉堡菜单,不过,正如视频中所说的那样

一个DrawerLayout应该只包含两个视图,一个用于ActivityFragment,一个用于NavigationView。

那么,是否有可能在拥有DrawerLayout的同时实现BottomNavigationView呢?如果是,怎么做?

这是我的activity_main.xml:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <FrameLayout
        android:id="@+id/framelayoutFragment"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintBottom_toTopOf="@+id/bottomNavigationView"
        app:layout_constraintTop_toTopOf="parent" />

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottomNavigationView"
        android:layout_width="match_parent"
        android:layout_height="56dp"
        app:backgroundTint="@color/colorSecondaryDark"
        app:elevation="0dp"
        app:itemIconTint="@drawable/selector"
        app:itemTextColor="@drawable/selector"
        app:labelVisibilityMode="selected"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:menu="@menu/menu_bottomnavgation" />

</androidx.constraintlayout.widget.ConstraintLayout>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-06-29 11:09:34

是的,您可以在拥有DrawerLayout的同时实现BottomNavigationView,尝试如下:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    tools:openDrawer="start"
    android:id="@+id/drawer_layout">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <androidx.appcompat.widget.Toolbar
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/tool_bar"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <FrameLayout
            android:id="@+id/frame"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            app:layout_constraintBottom_toTopOf="@id/btm_nav"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/tool_bar" />

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/btm_nav"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:menu="@menu/nav"
        android:background="#FFFFFF"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        />

</androidx.constraintlayout.widget.ConstraintLayout>

    <com.google.android.material.navigation.NavigationView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:id="@+id/nav_dr"
        app:menu="@menu/nav"
        android:layout_gravity="start"/>
</androidx.drawerlayout.widget.DrawerLayout>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62636584

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档