BottomNavigationView 使用

添加依賴:

    compile 'com.android.support:appcompat-v7:26.+'
    compile 'com.android.support:design:26.+'

注意: support:design的版本要和support:appcompat的版本一致。否則編譯不通過。

代碼中使用

layout布局:
<android.support.design.widget.BottomNavigationView
        android:id="@+id/bottom_navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/life_red"
        app:itemIconTint="@color/life_white"
        app:itemTextColor="@color/life_white"
        app:menu="@menu/menu_material_bottom_navigation"
        android:layout_gravity="bottom">

    </android.support.design.widget.BottomNavigationView>
menu布局
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:icon="@drawable/home_page_black"
        android:title="@string/home_page" />
    <item
        android:icon="@drawable/icons8_compass_96"
        android:title="@string/find" />
    <item
        android:icon="@drawable/icons8_product_96"
        android:title="@string/product" />
    <item
        android:icon="@drawable/icons8_user_96"
        android:title="@string/me" />
</menu>
默認效果
out.gif

為圖標(biāo)和字體換顏色

        app:itemIconTint="@color/life_white"
        app:itemTextColor="@color/life_white"

只能設(shè)置color不能設(shè)置drawable

  1. 在res目錄下創(chuàng)建color資源文件夾
  2. 創(chuàng)建selector文件material_bottom_navigation
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:color="@color/life_white" android:state_pressed="true"/>
    <item android:color="@color/life_white" android:state_checked="true"/>
    <item android:color="@color/life_black"/>
</selector
  1. 替換
        app:itemIconTint="@color/material_bottom_navigation"
        app:itemTextColor="@color/material_bottom_navigation"

問題

  • 當(dāng)item = 3個時,沒有動畫,大于3個 會出現(xiàn)上面的動畫效果。
  • 擴展性差

推薦文章:
https://juejin.im/post/59f924b0f265da431f4a60c3
http://www.itdecent.cn/p/aa499cc64f72
https://material.io/develop/android/components/bottom-navigation-view/

目前市面上有比較不錯的三方:
https://github.com/aurelhubert/ahbottomnavigation
https://github.com/chaychan/BottomBarLayout

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • afinalAfinal是一個android的ioc,orm框架 https://github.com/yangf...
    passiontim閱讀 15,889評論 2 45
  • afinalAfinal是一個android的ioc,orm框架 https://github.com/yangf...
    wgl0419閱讀 6,598評論 1 9
  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 179,167評論 25 708
  • 這篇文章主要解決兩個問題:1.自定義導(dǎo)航欄返回按鈕右滑返回手勢失效的問題。2.實現(xiàn)整個屏幕右滑就返回功能。(動畫效...
    PandaXiong閱讀 3,969評論 1 5
  • lavieena閱讀 144評論 0 0

友情鏈接更多精彩內(nèi)容