BottomNavigationView使用

  1. 设置显示模式
    app:labelVisibilityMode="labeled" |selected|unselected|auto

  2. 设置字体颜色
    app:itemTextColor="@drawable/sel_text_color_select"

    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:color="@color/black" android:state_selected="true"/>
        <item android:color="@color/gray_999999"/>
    selector>
    
  3. 设置按钮
    app:menu="@menu/main_bottom_tab"
    图片选择会失效,需要加上:

    mNavView.setItemIconTintList(null);
    
    <menu xmlns:android="http://schemas.android.com/apk/res/android">
        <item
            android:id="@+id/main_photo"
            android:icon="@drawable/sel_bottom_photo"
            android:title="照片"/>
    menu>
    
  4. 设置文字字体大小

        <dimen name="design_bottom_navigation_text_size" tools:override="true">10spdimen>
        <dimen name="design_bottom_navigation_active_text_size" tools:override="true">10spdimen>
    
  5. 设置图标距离顶部的距离

    <dimen name="design_bottom_navigation_margin" tools:override="true">10dpdimen>
    
  6. 事件监听

    mNavView.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
    

你可能感兴趣的:(Android组件)