android导航栏小部件

网友投稿 801 2022-11-01

android导航栏小部件

android导航栏小部件

Chip Navigation Bar

A navigation bar widget inspired on Google Bottom Navigation mixed with Chips component.

Usage

Vertical orientation

ChipNavigationBar supports a vertical orientation mode. This is very useful for tablets or devices with large screens.

Just add the attribute cnb_orientationMode to your xml:

... or programmatically call the method setMenuOrientation before inflate the menu:

menu.setMenuOrientation(MenuOrientation.VERTICAL)menu.setMenuResource(R.menu.my_menu)

Note: The view exposes methods to expand and collapse the menu but we don't provide the implementation for the toggle button. Check the sample for a basic implementation.

Badges

The library supports badges on the menu items.

menu.showBadge(R.id.menu_home) menu.showBadge(R.id.menu_activity, 8)menu.showBadge(R.id.menu_favorites, 88)menu.showBadge(R.id.settings, 10000)

XML custom attributes

MenuItem xml custom attributes

attributedescriptiondefault
android:ididrequired
android:enabledenabled statetrue
android:iconicon drawablerequired
android:titlelabel stringrequired
cnb_iconColorcolor used to tint the icon on selected stateR.attr.colorAccent
cnb_iconTintModePorterDuff.Mode to apply the color. Possible values: [src_over, src_in, src_atop, multiply, screen]null
cnb_textColorcolor used for the label on selected statesame color used for cnb_iconColor
cnb_backgroundColorcolor used for the chip backgroundsame color used for cnb_iconColor with 15% alpha

...

ChipNavigationBar xml custom attributes

attributedescriptiondefault
cnb_menuResourcemenu resource fileoptional since you can set this programmatically
cnb_orientationModemenu orientation. Possible values: [horizontal, vertical]horizontal
cnb_addBottomInsetproperty to enable the sum of the window insets on the current bottom padding, useful when you're using the translucent navigation barfalse
cnb_addTopInsetproperty to enable the sum of the window insets on the current bottom padding, useful when you're using the translucent status bar with the vertical modefalse
cnb_addLeftInsetproperty to enable the sum of the window insets on the current start padding, useful when you're using the translucent navigation bar with landscapefalse
cnb_addRightInsetproperty to enable the sum of the window insets on the current end padding, useful when you're using the translucent navigation bar with landscapefalse
cnb_minExpandedWidthminimum width for vertical menu when expanded0
cnb_unselectedColorcolor used for unselected state#696969
cnb_badgeColorcolor used for the badge#F44336
cnb_radiusradius used on the backgroundFloat.MAX_VALUE fully rounded
cnb_iconSizemenu item icon size24dp
cnb_textAppearancemenu item text appearancetheme default

Public API

methoddescription
setMenuResource(@MenuRes menuRes: Int)Inflate a menu from the specified XML resource
setMenuOrientation(menuOrientation: MenuOrientation)Set the menu orientation
setItemEnabled(id: Int, isEnabled: Boolean)Set the enabled state for the menu item with the provided [id]
setItemSelected(id: Int)Remove the selected state from the current item and set the selected state to true for the menu item with the [id]
setOnItemSelectedListener(listener: OnItemSelectedListener)Register a callback to be invoked when a menu item is selected
collapse()Collapse the menu items if orientationMode is VERTICAL otherwise, do nothing
expand()Expand the menu items if orientationMode is VERTICAL otherwise, do nothing
showBadge(id: Int)Display a numberless badge for the menu item with the [id]
showBadge(id: Int, count: Int)Display a countable badge with for the menu item with the [id]

Installation

Required

AndroidX - See migration guideAndroid Marshmallow - API Level 23

Gradle

Make sure that the repositories section includes JCenter

buildscript { ... repositories { jcenter() ... }

Add the library to the dependencies:

implementation 'com.ismaeldivita.chipnavigation:chip-navigation-bar:1.3.2'

Note: For projects without kotlin, you may need to add org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion to your dependencies since this is a Kotlin library.

License

MIT License

Copyright (c) 2019 Ismael Di Vita

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.

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:xs-vm- 小型虚拟机
下一篇:v2ex的vue小试项目
相关文章

 发表评论

暂时没有评论,来抢沙发吧~