Javad
Javad

Reputation: 6026

Using activities with BottomNavigationView

I'm integrating the new BottomNavigationView into an existing project. I wonder if there is a clean and smooth way (UX-wise) for using activities (instead of fragments) with this widget. We have complex activities which we rather not change in this iteration, and preferably not at all, because of separation of concerns. I have managed to use activities using the following approach, but it's jittery and the active tab indicator seems to reset itself before changing the tab.

Currently I have the bottom navigation bottom (exposed, protected) in my base activity (all other activities extend this class). In my item selected listener, I start other activities with an activity transition (to fade the bottom navigation view in current activity into the same view in the other (new) activity):

Bundle transition = ActivityOptionsCompat.makeSceneTransitionAnimation(
          getActivity(), bottomNavigationView, TRANSITION_NAME).toBundle();

And pass this bundle to startActivity() method. I also call overridePendingTransition() for a smoother transition, but all in all this is still jittery and as I mentioned there is a problem with the active tab indicator. Needless to say you have to handle changing the checked state of the view by yourself. For my toy project, I do this the following way (in OnCreate() of my activities):

bottomNavigationView.getMenu().getItem(1).setChecked(false);
bottomNavigationView.getMenu().getItem(2).setChecked(false);
bottomNavigationView.getMenu().getItem(3).setChecked(false);
bottomNavigationView.getMenu().getItem(4).setChecked(false);

bottomNavigationView.getMenu().getItem(0).setChecked(true);

Is there a way to use activities with a smooth user experience?

Upvotes: 4

Views: 1989

Answers (1)

yoco
yoco

Reputation: 11

you can do that as style.xml

style.xml

<style name="AppTheme> <item name="android:windowAnimationStyle">@null</item> <style>

and, manifest.xml

<activity android:theme="@style/AppTheme" />

Upvotes: 1

Related Questions