I've implemented new BottomNavigationView (com.android.support:design:25.0.0) and have no idea how to set selection index or MenuItem
id (in my case, mid item should be selected by default). I'm afraid there's no such possibility for now as far as it's too raw yet, but anyway any help will be appreciated. Thanks!
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
You can extend BottomNavigationView and use reflection to invoke private methods.
Set the selected menu item ID using
setSelectedItemId
:This method started being available from Android Support Library 25.3.0.
The only solution that worked for me is:
Simply performing click does the trick. Hope we'll have extra methods/properties in future releases.
UPD:
As user5968678 mentioned, new method was added since Android Support Library v25.3.0:
so use in instead :)
Stop using Reflection! It is bad!
Well, while the support library does not gives us the option to select the item from the BottomNavigationView to be displayed on the first time when it is visible, we have two possibilities:
When the setupBottomNavigationView() method is executed? In Activity onCreate() method, take a look:
Simple and without extensive code.
Hope it helps!
If you're using listener, like default implementation in android studio, try this:
I believe the question in this context is being viewed in different contexts basing on answers here. According to assessment, whats required is ability to focus on specific
BottomNavigationView
item (definitely in new class holding different fragments).Now, you could have BottomNavigationView OR Buttons or Anything clickable to launch new activity on intent : - i.e
Then -in our New_Activity, we receive the intent-
Intent intent = getIntent(); int page = intent.getExtras().getInt("EXTRA_PAGE);
We then loop over the page variable to find the number/Index for which the current BottomNavigationView is reflecting , THEN we set our focus menu item (assuming your BottomNavigationView has Menu Item for its display)
This answers the question above. The rest of Fragment switch is handled well by number of posts above by invoking :
Then something like :
NOTE: Using BottomNavigationView and ContentFrameLayout is soo economical and will slash down your code to over 50 % unlike using likes of ViewPager and Tablayout