Search code examples
androidandroid-fragmentsandroid-activitybottombar

How we can use single BottomBar in whole Application like ActionBar in Android


I use https://github.com/roughike/BottomBar module for implement bottombar feature in application

The problem is that i include a BottomBar layout in each activity

Is there any way how can i use BottomBar in only once therefore I am able to use that single BottomBar in whole Application?


Solution

  • I found one best solution for use single BottomBar in whole Applicaiton I create single Activity that is MainActivity and rest of all Fragments

    Generally when we replace fragment with another fragment, we can't get previous fragment for that solution i write below code

    FragmentManager fm;
    FragmentTransaction fragmentTransaction;
    
    public ProductListAdapter(Context context, List<ProductItem> items, FragmentManager fm) {
            super(context, 0, items);
            this.fm = fm;
            fragmentTransaction = fm.beginTransaction();
            layoutInflater = LayoutInflater.from(context);
    }
    
    btnProductMainViewMore.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
    
                        fragmentTransaction.setCustomAnimations(android.R.anim.fade_in,
                                android.R.anim.fade_out);
                        fragmentTransaction.replace(R.id.frame, new ProductDetailFragment());
                        **fragmentTransaction.addToBackStack(null);** // with this line you can back to previous fragment
                        fragmentTransaction.commit();
                    }
                });