I am trying to animate between the fragments. I am using FragNav library to manage the fragment. I have looked out almost all answer related to fragment transition but can't sort the problem. Can anyone assist me. I am also using bottom tab bar to navigate into fragments.
Here is my MainActivity
public class MainActivity extends AppCompatActivity {
private FragNavController fragNavController;
//indices to fragments
private final int TAB_FIRST = FragNavController.TAB1;
private final int TAB_SECOND = FragNavController.TAB2;
private final int TAB_THIRD = FragNavController.TAB3;
private final int TAB_FOURTH = FragNavController.TAB4;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//FragNav
//list of fragments
List<Fragment> fragments = new ArrayList<>(4);
//add fragments to list
fragments.add(TrackFragment.newInstance(0));
fragments.add(SecureFragment.newInstance(0));
fragments.add(AlertsFragment.newInstance(0));
fragments.add(MoreFragment.newInstance(0));
//link fragments to container
fragNavController = new FragNavController(getSupportFragmentManager(),R.id.container,fragments);
// FragNavController.setTransitionMode(R.anim.slide_in_left, R.anim.slide_in_right);
FragNavController.setTransition(R.anim.slide_in_left, R.anim.slide_out_right);
FragNavController.setTransitionMode();
//End of FragNav
AHBottomNavigation bottomNavigation = (AHBottomNavigation) findViewById(R.id.bottom_navigation);
// Create items
AHBottomNavigationItem item1 = new AHBottomNavigationItem(R.string.tab_1, R.drawable.track_g, R.color.white);
AHBottomNavigationItem item2 = new AHBottomNavigationItem(R.string.tab_2, R.drawable.car_g, R.color.white);
AHBottomNavigationItem item3 = new AHBottomNavigationItem(R.string.tab_3, R.drawable.alarm_g, R.color.white);
AHBottomNavigationItem item4 = new AHBottomNavigationItem(R.string.tab_4, R.drawable.more_g, R.color.white);
// Add items
bottomNavigation.addItem(item1);
bottomNavigation.addItem(item2);
bottomNavigation.addItem(item3);
bottomNavigation.addItem(item4);
// Set background color
bottomNavigation.setDefaultBackgroundColor(Color.parseColor("#FFFFFF"));
// Change colors
bottomNavigation.setAccentColor(Color.parseColor("#F63D2B"));
bottomNavigation.setInactiveColor(Color.parseColor("#747474"));
// Force to tint the drawable (useful for font with icon for example)
bottomNavigation.setForceTint(true);
// Manage titles
bottomNavigation.setTitleState(AHBottomNavigation.TitleState.ALWAYS_SHOW);
// Set current item programmatically
bottomNavigation.setCurrentItem(1);
// Set listeners
bottomNavigation.setOnTabSelectedListener(new AHBottomNavigation.OnTabSelectedListener() {
@Override
public boolean onTabSelected(int position, boolean wasSelected) {
if (position == 0){
fragNavController.switchTab(TAB_FIRST);
}
if (position == 1){
fragNavController.switchTab(TAB_SECOND);
}
if (position == 2){
fragNavController.switchTab(TAB_THIRD);
}
else if (position == 3){
fragNavController.switchTab(TAB_FOURTH);
}
return true;
}
});
}
}
Finally got the answer .
setTransitionMode()
is not a static method so need to be used it from an instance of the FragNavController object.