从上图可以看到,在底部导航视图的顶部有一条高度为1dp且宽度与父级匹配的线。如何制作这样的水平线?
我试图像这样在底部视图中添加该行
<com.google.android.material.bottomnavigation.BottomNavigationView
android:layout_width="0dp"
android:layout_height="50dp"
app:elevation="0dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:background="@color/grey_light_medium"
app:itemIconTint="@color/bottom_navigation_color"
app:itemTextColor="@color/bottom_navigation_color"
app:menu="@menu/bottom_navigation_menu"
app:labelVisibilityMode="unlabeled"
android:id="@+id/bottom_nav">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<view
android:layout_width="match_parent"
android:layout_height="1dp"
app:layout_constraintTop_toTopOf="parent"
android:background="@color/grey_dark_top">
</view>
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.bottomnavigation.BottomNavigationView>
但是我的应用程序崩溃并显示错误消息:
原因:java.lang.NullPointerException:尝试调用虚拟 null上的方法'boolean java.lang.String.equals(java.lang.Object)' 对象引用
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main) <--- on this line in my Activity
}