android - BottomNavigationView 不是全宽

标签 android material-design bottom-sheet

我正在开发一个 Android 应用程序并从设计库中实现 BottomNavigationView。我查看了许多示例,但无法弄清楚我的布局有什么问题。 BottomNavigationView 未显示为全宽。

另一个问题是没有应用状态栏颜色。

enter image description here

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<!-- Include the toolbar -->
<include layout="@layout/toolbar"/>

<RelativeLayout android:id="@+id/fragment_container"
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>


<android.support.design.widget.BottomNavigationView
    android:id="@+id/bottom_navigation"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_gravity="bottom"
    app:itemBackground="@color/colorPrimary"
    app:itemIconTint="@android:color/white"
    app:itemTextColor="@android:color/white"
    app:menu="@menu/bottom_navigation_main"/>

</android.support.design.widget.CoordinatorLayout>

工具栏.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.AppBarLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    app:popupTheme="@style/AppTheme.PopupOverlay"/>

</android.support.design.widget.AppBarLayout>

编辑: 增加了未设置状态颜色的解决方案

android:fitsSystemWindows="true"

(colorPrimaryDark) status bar color not working on android v21?

最佳答案

The BottomNavigationView is not displayed as full width.

这是不应该的。

根据design guidelines Action 的宽度可以在 80dp 和 168dp 之间变化。您定义的两个 Action 不足以水平填充整个区域。
(作为旁注,同样根据指南, View 应该包含三到五个 Action 。)

如果要填充BottomNavigationView后面的空间,可以将view的背景颜色设置为与items背景颜色相同:

<android.support.design.widget.BottomNavigationView
     android:background="@color/bottom_view_color"
     app:itemBackground="@color/bottom_view_color"

     // .... />

关于android - BottomNavigationView 不是全宽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41432902/

相关文章:

android - Material Theme Light.DarkActionBar 中的文本颜色不浅

Android 支持 BottomSheetBehavior 附加锚定状态

android - 来自模态 BottomSheetFragment 的 BottomSheetCallback

带 Volley 的 Android MVP

android - 我的应用程序如何知道用户何时从其 Android 原生 Facebook 应用程序注销?

android - 在项目来自服务器的微调器上添加 "Select item"

android - 如何在 Android 上的 textview 或 imageview 上设置涟漪效果?

Angular Material 2 无法抑制所需的星号

android - 带有全屏工具栏和软键盘的模态 BottomSheetDialog

android - getContactsFromFirebase() 方法返回一个空列表