android bottom bar setting default tab on create of an activity
See original GitHub issueMyself trying to develop a sample android app based on this tutorial with bottom bar.
`protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.thirdactivity);
BottomBar bottomBar = BottomBar.attach(this, savedInstanceState);
bottomBar.setItemsFromMenu(R.menu.bottom_menu, new OnMenuTabSelectedListener() {
@Override
public void onMenuItemSelected(int itemId) {
Intent myAct = new Intent();
switch (itemId) {
case R.id.item1:
myAct = new Intent(findViewById(itemId).getContext(), mainactivity.class);
break;
case R.id.item2:
myAct = new Intent(findViewById(itemId).getContext(), secondactivity.class);
break;
case R.id.item3:
myAct = new Intent(findViewById(itemId).getContext(), thirdactivity.class);
break;
}
startActivity(myAct);
}
});
}`
But how can i set the third tab as default oncreate the activity. The above code highlights the first tab as selected and no even listened when clicking on first tab. Also later tabs opens the respective activities but not highlights as current tab.
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (1 by maintainers)
Top Results From Across the Web
android bottom bar setting default tab on create of an activity
It is solved by having startActivity() as, BottomBar bottomBar = BottomBar.attach(this, savedInstanceState); bottomBar.setItemsFromMenu(R.menu.bottom_menu, ...
Read more >How to Code a Bottom Navigation Bar for an Android App
Open Android Studio, create a new project, and select a Blank Activity template, as shown below. Select the Kotlin language from the drop-down ......
Read more >Set up the app bar - Android Developers
Set up the app bar ... In its most basic form, the action bar displays the title for the activity on one side...
Read more >Bottom Navigation Bar in Android - GeeksforGeeks
It allows the user to switch to different activities/fragments easily. ... Step 4: Creating a menu for the Bottom Navigation Bar.
Read more >Bottom Tab Bar Example Fragments Android Studio Kotlin ...
How to create simple tabbar app using tab layout, fragments and view pager in Android Studio using Kotlin. Bottom navigation for android.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@mpsbhat Try setting the default tab before your set the listener
This applies for version
2.0.2If you set the listener before the default tab, it will be called twice. Once for tab position 0 and then for anything you set as default, which is usually not desired.
@roughike Would be nice to set the default tab before the the creation of bottombar, or a warning in the readme.
Myself can use
bottomBar.setDefaultTabPosition(desiredTabId);to set the default tab. But uses higher memory and application gets slow down and sometime crashes. What is the fix?