#Android开发杂记--BottomNavigationView的一些注意事项

#Android开发杂记--BottomNavigationView的一些注意事项

图标无法显示,变成小色块?

你是否遇到过如下的情况?当使用官方的BottomNavigationView时,添加的图标变成小色块。

此时只需要在系统自动生成的MainActivity的onCreate方法里追加一句话即可:

// 自动生成的模板代码
BottomNavigationView navView = findViewById(R.id.nav_view);
// 需要追加的代码
navView.setItemIconTintList(null);

想要加上或者去除动画效果?

系统默认当底部导航小于等于3个时,没有动画效果,而当底部导航大于三个时,有动画效果(不能大于5个,否则程序会崩溃)。
只需要在xml布局文件中增加属性
app:labelVisibilityMode=“selected|labeled|unlabeled|auto”
例如:

    <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"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:itemTextColor="@color/black"
        app:menu="@menu/bottom_nav_menu" 
      	<!-- 下面一行就是需要新增的属性 -->
        app:labelVisibilityMode="selected"
/>

猜你喜欢

转载自blog.csdn.net/qq_43519779/article/details/114270706