android菜单栏库,SmoothBottomBar 一个轻量级的Android material底部导航栏库

SmoothBottomBar

A lightweight Android material bottom navigation bar library

68747470733a2f2f6a69747061636b2e696f2f762f6962726168696d736e39382f536d6f6f7468426f74746f6d4261722e73766768747470733a2f2f696d672e736869656c64732e696f2f62616467652f4150492d31362532422d627269676874677265656e2e7376673f7374796c653d666c617468747470733a2f2f696d672e736869656c64732e696f2f62616467652f416e64726f6964253230417273656e616c2d536d6f6f7468426f74746f6d4261722d677265656e2e7376673f7374796c653d666c617468747470733a2f2f616e64726f69647765656b6c792e6e65742f6973737565732f69737375652d3338352f6261646765

GIF

1fb03903d0cd901e5c7b99b8091bca55.gif

Design Credits

All design and inspiration credits belong to Alejandro Ausejo.

Usage

Create menu.xml under your res/menu/ folder

android:id="@+id/item0"

android:title="@string/menu_dashboard"

android:icon="@drawable/ic_dashboard_white_24dp"/>

android:id="@+id/item1"

android:title="@string/menu_leaderboard"

android:icon="@drawable/ic_multiline_chart_white_24dp"/>

android:id="@+id/item2"

android:title="@string/menu_store"

android:icon="@drawable/ic_store_white_24dp"/>

android:id="@+id/item3"

android:title="@string/menu_profile"

android:icon="@drawable/ic_person_outline_white_24dp"/>

Add view into your layout file

android:id="@+id/bottomBar"

android:layout_width="match_parent"

android:layout_height="70dp"

app:backgroundColor="@color/colorPrimary"

app:menu="@menu/menu_bottom"/>

Use SmoothBottomBar callbacks in your activity

bottomBar.onItemSelected = {

status.text = "Item $it selected"

}

bottomBar.onItemReselected = {

status.text = "Item $it re-selected"

}

OR

bottomBar.setOnItemSelectedListener(object: OnItemSelectedListener {

override fun onItemSelect(pos: Int) {

status.text = "Item $pos selected"

}

})

bottomBar.setOnItemReselectedListener(object: OnItemReselectedListener {

override fun onItemReselect(pos: Int) {

status.text = "Item $pos re-selected"

}

})

Use SmoothBottomBar with Navigation Components.

Coupled with the Navigation Component from the Android Jetpack, SmoothBottomBar offers easier navigation within your application by designating navigation to the Navigation Component. This works best when using fragments, as the Navigation component helps to handle your fragment transactions.

Setup Navigation Component i.e. Add dependenccy to your project, create a Navigation Graph etc.

For each Fragment in your Navigation Graph, ensure that the Fragment's id is the same as the MenuItems in your Menu i.e res/menu/ folder

android:id="@+id/first_fragment"

android:title="@string/menu_dashboard"

android:icon="@drawable/ic_dashboard_white_24dp"/>

android:id="@+id/second_fragment"

android:title="@string/menu_leaderboard"

android:icon="@drawable/ic_multiline_chart_white_24dp"/>

android:id="@+id/third_fragment"

android:title="@string/menu_store"

android:icon="@drawable/ic_store_white_24dp"/>

android:id="@+id/fourth_fragment"

android:title="@string/menu_profile"

android:icon="@drawable/ic_person_outline_white_24dp"/>

Navigation Graph i.e res/navigation/ folder

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:id="@+id/nav_graph"

app:startDestination="@id/first_fragment">

android:id="@+id/first_fragment"

android:name="me.ibrahimsn.smoothbottombar.FirstFragment"

android:label="First Fragment"

tools:layout="@layout/fragment_first" />

android:id="@+id/second_fragment"

android:name="me.ibrahimsn.smoothbottombar.SecondFragment"

android:label="Second Fragment"

tools:layout="@layout/fragment_second" />

android:id="@+id/third_fragment"

android:name="me.ibrahimsn.smoothbottombar.ThirdFragment"

android:label="Third Fragment"

tools:layout="@layout/fragment_third" />

android:id="@+id/fourth_fragment"

android:name="me.ibrahimsn.smoothbottombar.FourthFragment"

android:label="Fourth Fragment"

tools:layout="@layout/fragment_fourth" />

In your activity i.e MainActivity, override onCreateOptionsMenu, get a reference to your SmoothBottomBar and call setupWithNavController() which takes in a Menu and NavController on the SmoothBottomBar.

override fun onCreateOptionsMenu(menu: Menu?): Boolean {

menuInflater.inflate(R.menu.menu_bottom,menu)

bottomBar.setupWithNavController(menu!!,navController)

return true

}

You can also setup your ActionBar with the Navigation Component

private lateinit var navController: NavController

override fun onCreate(savedInstanceState: Bundle?) {

super.onCreate(savedInstanceState)

navController = findNavController(R.id.fragment)

setupActionBarWithNavController(navController)

}

override fun onCreateOptionsMenu(menu: Menu?): Boolean {

menuInflater.inflate(R.menu.menu_bottom,menu)

bottomBar.setupWithNavController(menu!!,navController)

return true

}

override fun onSupportNavigateUp(): Boolean {

navController.navigateUp()

return true

}

Result:

smooth_bar_gif.gif?raw=true

Customization

android:id="@+id/bottomBar"

android:layout_width="match_parent"

android:layout_height="70dp"

app:menu=""

app:backgroundColor=""

app:indicatorColor=""

app:indicatorRadius=""

app:sideMargins=""

app:itemPadding=""

app:textColor=""

app:itemFontFamily=""

app:textSize=""

app:iconSize=""

app:iconTint=""

app:iconTintActive=""

app:activeItem=""

app:duration="" />

Setup

allprojects {

repositories {

...

maven { url 'https://jitpack.io' }

}

}

dependencies {

implementation 'com.github.ibrahimsn98:SmoothBottomBar:1.7.6'

}

Contributors

License

MIT License

Copyright (c) 2019 İbrahim Süren

Permission is hereby granted, free of charge, to any person obtaining a copy

of this software and associated documentation files (the "Software"), to deal

in the Software without restriction, including without limitation the rights

to use, copy, modify, merge, publish, distribute, sublicense, and/or sell

copies of the Software, and to permit persons to whom the Software is

furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all

copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR

IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE

AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER

LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,

OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE

SOFTWARE.

Follow me on Twitter @ibrahimsn98

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值