java - Android中BottomNavigationView的分隔符
解决方案
您可以按照此处的建议为BottomNavigationView创建背景。如果您已经有背景并且由于BottomNavigationView是FrameLayout,则可以添加一个分隔符,如下所示:
navigation_divider.xml
<shape
android:shape="rectangle">
<size android:width="2dp" />
<solid android:color="#E91E63" />
</shape>
activity_main.xml
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="?attr/actionBarSize">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/nav_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/bottom_nav_menu">
<View
android:layout_width="2dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:background="@drawable/navigation_divider" />
</com.google.android.material.bottomnavigation.BottomNavigationView>
<fragment
android:id="@+id/nav_host_fragment_activity_main"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:layout_constraintBottom_toTopOf="@id/nav_view"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="@navigation/mobile_navigation" />
</androidx.constraintlayout.widget.ConstraintLayout>
当然,您需要在菜单中选择偶数个选项。
推荐阅读
- c# - 在 C# 中将数字字符串转换为枚举
- uwp - 如何添加空白 UWP 应用作为另一个空白 UWP 应用的参考?
- r - 将一个列表中的数据框行绑定到另一个列表中的数据框
- angular - 材质对话框没有响应
- javascript - AES 加密/解密代码 Javascript(在浏览器中)
- python-logging - 如何记录 swagger / connexion 请求正文?
- python - Selenium 错误:AttributeError:“WebDriver”对象没有属性“Firefox”
- ios - 如何在继续之前连续检查是否按下了某个键?
- php - 为什么网站使用与 localhost 不同版本的 PHP?
- android - 更改广播接收器中的文本