I've followed Google's recommended implementation of the Navigation Drawer and now have an introductory Fragment and Map fragment that I transition between. The drawer worked smoothly until I added ActionBarSherlock to my project. Now, when the home (original fragment) is selected the menu is delayed closing and I get an annoying flash before the home fragment appears.
The fragment transaction is handled by:
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction
.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out)
.replace(R.id.content_frame, fragment, null)
.commit();
Any suggestions are welcome.
Related
Navigation Flow in android Fragment such as push and pop with proper example ,
FragmentTransaction fragmentTransaction4 = getFragmentManager().beginTransaction();
fragmentTransaction4.addToBackStack(null);
fragmentTransaction4.replace(R.id.main_frame, passportFragment);
fragmentTransaction4.commit();
I wanted to know how I can get the Fragment which is onloaded on my Acticvity.
The background behind this is, that I want to change the onBackPressed method that it's switching to the right fragments. At the moment when I press "Back" the app closes, because I work alot with fragments.
Use addToBackStack on your fragment transaction. This way when you press the back key the transaction gets rolled back and thus your fragment disappears.
I got a solution for the problem:
Fragment fragment = new Fragment();
FragmentManager manager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = manager.beginTransaction();
fragmentTransaction.add(R.id.Layout,Fragment);
fragmentTransaction.addToBackStack("flow1");
fragmentTransaction.commit();
I am building an Expense Keeping app with React-Native on Android. Below is the UI flow chart of my app:
I wish to use the Drawer to navigate between top level scenes (shown in dark red).
In the Settings scene, there are options that require to navigate to a group of 2nd level scenes which can only navigate back to the Settings scene (shown in blue).
I want my Navigation bar to persist across scene transitions, so I am using the navigationBar props of the <Navigator> component.
Using a single <Navigator> as the top component in my app and manage all the scenes and routes with it is an obvious solution but this way it is harder to manage the "levels" of scenes.
I would like to know if there are any other better ways to structure the <Navigator> in my app, perhaps nesting navigators?
I know this is an old question, but it is still relevant and just to keep this up-to-date, use React-Navigation (Warning: requires some learning and practice). You can use this example. Look out for the navigation tree in that. It is similar to what the question needs.
Have you tried react-native-router-flux component?
You can using Fragment.
First: In Activity. You create Navigatior.
in xml of Activity have:
<DrawerLayout>
<Toolbar> or (Control Home of you)
<FrameLayout id="content_main">
Then: You create SettingFragment extend Fragment
HomeFragment extend Fragment
ExpansesFragment extend Fragment
import support.v4.Fragment
In Activity extend Activity
onCreate:
FragmentManager manager = getSupportFragmentManager();
manager.beginTransaction()
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.replace(R.id.content_main, HomeFragment)
.commit();
On Drawer. event Onclick
Home
FragmentManager manager = getSupportFragmentManager();
manager.beginTransaction()
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.replace(R.id.content_main, HomeFragment)
.commit();
Expenses
FragmentManager manager = getSupportFragmentManager();
manager.beginTransaction()
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.replace(R.id.content_main, ExpensesFragment)
.commit();
Category
FragmentManager manager = getSupportFragmentManager();
manager.beginTransaction()
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.replace(R.id.content_main, CategoryFragment)
.commit();
On navigating from one fragment to another which are part of same activity, I am using slide animation.
WebFragment fragment = WebFragment.newInstance(Globals.TGURL_CREATE_ACTIVITY, "");
FragmentManager fm = getActivity().getSupportFragmentManager();
FragmentTransaction transaction = fm.beginTransaction();
transaction.setCustomAnimations(R.anim.enter_anim, R.anim.exit_anim, R.anim.enter_anim, R.anim.exit_anim);
transaction.replace(R.id.fragment_activity_layout, fragment);
transaction.addToBackStack(null);
transaction.commit();
This code ensures that when I come back to the first fragment, animation is there.
Well this has been a boon for me so far. But in one specific case it is becoming a curse. The activity is placed on ActionBar tab. When the 2nd (WebFragment) is the current one, and I tap the tab and not the back button, I want the first fragment to be displayed without any animation.
But it has been impossible for me to do this so far as the navigation is inheriting the animation which was earlier given.
This is what I am doing for going back :
TabActivity.this.getSupportFragmentManager().popBackStack();
When click the items of NavigationDrawer,The main activity container switch the fragments to show,It worked fine until I met this:
1.Switched to FragmentA, which CONTAINS A VIEWPAGER,it showed well.
2.Switched to fragmentB,fragmentB showed well.
3.Swiched back to
FragmentA,it shows as a Blank View
I tried to flip horizontally on it,I can see the viewpager index do changed(in log),But I don't know why it showed as a blank page.
*and,if fragmentA dose not contains viewpager,it worked well
Any suggestion would be appreciated.
I use replace() to switch between the fragments:
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.container, currentFragment)
.commit();
Possible reason might be not using replace transaction instead you mightbe adding fragments and adding it to backstack. Try using replace transaction, and see if it works.
Fragment1 firstFragment = new Fragment1();
Bundle bundle = new Bundle();
firstFragment.setArguments(bundle);
getSupportFragmentManager().beginTransaction()
.replace(R.id.article_fragment, firstFragment)
.commit();
Learn More on Fragments adding to back stack:
Android Fragment transaction: FragmentManager and Backstack