Navigation drawer with Activity and child Fragments

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-03 08:48:15

问题


I have a Activity A, a ListFragment P and 2 Fragments Q and R.

When the app is launched, A is created, which loads P. Based on what user clicks, it is replaced by Q or R.

Now by referencing this tutorial, I have implemented a Navigation Drawer which shows certain items to the user. However, since I have implemented the Navigation Drawer in the Activity, it shows for all the Fragments. I want it to be only available to P.

(Very much similar to Googles Gmail app. When the user is on the main screen - the drawer is present. When user taps to open an email, the drawer changes to back button)

I am not sure how to translate the above code. Any help is appreciated.


回答1:


I solved this issue by simply overriding the up carat behavior by calling the mDrawerToggle.setDrawerIndicatorEnabled(enable) and passing the boolean enable or disable as needed.

(The fragments where I didn't want the drawer to show called this method with false and where I wanted the drawer to be shown called this method with true. I put the call inside the onResume() of the respective fragment for obvious reasons.)

This works exactly like I want, and I did not have to change the design of my project :).




回答2:


What you can do is create a new FragmanetActivity S and replace Q and R accordingly. If you are app is for Android 3.0 lower user ActionBarActivity create a actionbar and set its setDisplayHomeAsUpEnabled(true). As the new FragmentActivity will have new layout there will be no NavigationDrawer.



来源:https://stackoverflow.com/questions/22316640/navigation-drawer-with-activity-and-child-fragments

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!