我正在开发一个 Android 应用程序并从设计库中实现 BottomNavigationView
。我查看了许多示例,但无法弄清楚我的布局有什么问题。 BottomNavigationView
未显示为全宽。
另一个问题是没有应用状态栏颜色。
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/