Last active
March 4, 2021 20:35
-
-
Save Kaspic/b6b6f725abb498ac75dd8b2aa3bd300f to your computer and use it in GitHub Desktop.
https://medium.com/codex/android-material-navigation-rail-d44eeb27d111 - Navigation Rail Early Look
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// If you don't add a number, only a badge will be displayed at the respective menu_item | |
var badge = findViewById<NavigationRailView>(R.id.navigation_rail).getOrCreateBadge(R.id.menu_item_account) | |
badge.isVisible = true | |
// In this case, the number 99 will be displayed in the badge | |
badge = findViewById<NavigationRailView>(R.id.navigation_rail).getOrCreateBadge(R.id.menu_item_moon) | |
badge.isVisible = true | |
badge.number = 99 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dependencies { | |
// ... | |
implementation 'com.google.android.material:material:1.4.0-alpha01' | |
// ... | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NavigationRailView.OnNavigationItemSelectedListener { item -> | |
when(item.itemId) { | |
R.id.menu_item_account -> { | |
// Account item in NavigationRail clicked | |
true | |
} | |
R.id.menu_item_moon -> { | |
// Moon item in NavigationRail clicked | |
true | |
} | |
R.id.menu_item_time -> { | |
// Time item in NavigationRail clicked | |
true | |
} | |
else -> false | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment