question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

android bottom bar setting default tab on create of an activity

See original GitHub issue

Myself 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:closed
  • Created 7 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
ArthurSavcommented, Oct 31, 2016

@mpsbhat Try setting the default tab before your set the listener

bottomBar.setDefaultTab(R.id.tab_default);
bottomBar.setOnTabSelectListener(this);

This applies for version 2.0.2

If 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.

1reaction
mpsbhatcommented, Sep 8, 2016

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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found