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.
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?
@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.
getting error, "cannot resolve method setDefaultTab"
@Sai-Kranti it is there on the latest version, and i'm pretty sure is there for almost all 2.0+ version
public void setDefaultTab(@IdRes int defaultTabId)
but, what if i am using 1.0.2 ?
@Sai-Kranti is there any reason why are you using that version instead of the newest version?
if i am using the newest, i am getting error here
compile 'com.android.support:appcompat-v7:25.3.0'
@Sai-Kranti that's because you are using a different version than the one used by the library, which is 25.1.0, so, they way you fix that is by specifying that you want the 25.3.0 version to be used and upgrade all the ones using older version, you can easily do a StackOverflow search to know how to resolve library version conflicts, but, is not related to this issue.
Yep, the reason for that is that the library uses different version.
You can force the version to whichever you like in your app-level build.gradle.
configurations.all {
resolutionStrategy.force 'com.android.support:appcompat-v7:x.y.z'
}
Most helpful comment
@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.