All Projects → okaybroda → FragmentStateManager

okaybroda / FragmentStateManager

Licence: MIT License
An Android library that holds fragment states for bottom navigation view even when activity rotates.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to FragmentStateManager

SwiTAS
A usable toolkit for creating Nintendo Switch TASes with homebrew
Stars: ✭ 54 (+0%)
Mutual labels:  savestate
stater
Android library for easy save data to bundle in Activity/Fragment.
Stars: ✭ 12 (-77.78%)
Mutual labels:  savestate
BottomNavygation
Bottom Navigation based on Bottom Navigation View from Android
Stars: ✭ 62 (+14.81%)
Mutual labels:  bottomnavigationview
BottomNavigationCircularColorReveal
Build a BottomNavigationView with a circular color reveal animation like in Material Design guidelines demos.
Stars: ✭ 24 (-55.56%)
Mutual labels:  bottomnavigationview
bottomnavigationviewex-android-binding
Xamarin.Android Binding Library for Ittianyu BottomNavigationViewEx
Stars: ✭ 25 (-53.7%)
Mutual labels:  bottomnavigationview
BetterBottomBar
Fork of the BottomNavigationView from the design lib to allow for view state, accessibility and colorful animations
Stars: ✭ 33 (-38.89%)
Mutual labels:  bottomnavigationview
BottomNavArchDemo
The demo project for Bottom Navigation with Navigation Architecture Components article
Stars: ✭ 53 (-1.85%)
Mutual labels:  bottomnavigationview
flutter-bottomAppBar
Watch the tutorial video on Youtube ->
Stars: ✭ 15 (-72.22%)
Mutual labels:  bottomnavigationview
Motion-Tab-Bar
A beautiful animated flutter widget package library. The tab bar will attempt to use your current theme out of the box, however you may want to theme it.
Stars: ✭ 237 (+338.89%)
Mutual labels:  bottomnavigationview
BottomNavigation-RichPath-Sample
BottomNavigation RichPath Sample
Stars: ✭ 76 (+40.74%)
Mutual labels:  bottomnavigationview
BottomNavigationViewDemo
BottomNavigationView + Fragment 学习Demo
Stars: ✭ 22 (-59.26%)
Mutual labels:  bottomnavigationview
BottomNavigationBar
A light bottom navigation bar in Android supporting Tint mode.
Stars: ✭ 48 (-11.11%)
Mutual labels:  bottomnavigationview
Bubble Navigation
🎉 [Android Library] A light-weight library to easily make beautiful Navigation Bar with ton of 🎨 customization option.
Stars: ✭ 1,537 (+2746.3%)
Mutual labels:  bottomnavigationview
Bottomnavigationviewex
An android lib for enhancing BottomNavigationView. 一个增强BottomNavigationView的安卓库。
Stars: ✭ 3,259 (+5935.19%)
Mutual labels:  bottomnavigationview
IRBottomNavigationView
Floating Bottom Navigation/Tab System
Stars: ✭ 48 (-11.11%)
Mutual labels:  bottomnavigationview
bottom-navigation
Example of Android BottomNavigationView
Stars: ✭ 104 (+92.59%)
Mutual labels:  bottomnavigationview
BottomNavigationView
Bottom Navigation Example
Stars: ✭ 15 (-72.22%)
Mutual labels:  bottomnavigationview
Android Tips
An awesome list of tips for Android.
Stars: ✭ 3,239 (+5898.15%)
Mutual labels:  android-fragments
update-and-replace-fragment-in-viewpager
Android: Show how to update and replace Fragment in ViewPager
Stars: ✭ 102 (+88.89%)
Mutual labels:  android-fragments

FragmentStateManager

An Android library that holds fragment states for BottomNavigationView. Saves fragment back stack even after activity rotation. Implementation derived from FragmentStatePagerAdapter.

Installation

Add Jitpack to project level gradle file

allprojects {
    repositories {
        maven { url "https://jitpack.io" }
    }
}

Then add library to module level gradle file

dependencies {
  compile 'com.github.okaybroda:FragmentStateManager:1.+'
}

Usage

Create a FragmentStateManager instance in the OnCreate function of your Activity

FragmentStateManager fragmentStateManager;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // ... your code ...
    FrameLayout content = findViewById(R.id.content);
    fragmentStateManager = new FragmentStateManager(content, getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                switch (position) {
                    case 0:
                        return new MainFragment();
                    case 1:
                        return new SearchFragment();
                    case 2:
                        return new MeFragment();
                }
            }
        };
}

To change current fragment, call

fragmentStateManager.changeFragment(0); // 0 is the index of the fragment

Integration with BottomNavigationView

Add item selected listener

navigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
    @Override
    public boolean onNavigationItemSelected(@NonNull MenuItem item) {
        int position = getNavPositionFromMenuItem(item);
        if (position != -1) {
            fragmentStateManager.changeFragment(getNavPositionFromMenuItem(item));
            return true;
        }

        return false;
    }
});

(Optional) Add item reselected listener. This will reset the fragment to it's original state

navigation.setOnNavigationItemReselectedListener(new BottomNavigationView.OnNavigationItemReselectedListener() {
    @Override
    public void onNavigationItemReselected(@NonNull MenuItem item) {
        int position = getNavPositionFromMenuItem(item);
        if (position != -1) {
            fragmentStateManager.removeFragment(position);
            fragmentStateManager.changeFragment(position);
        }
    }
});
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].