I'm using developer.android.com guides to build an app. I choosed "Navigation: Navigation Drawer" when I made a new project in Android Studio. I have searched the internet for answers to my questions but I can't find any that works. Sorry about this, I'm new to programming.
- How do I make my app open a new fragment in the main view when clicking in the navigation drawer?
- Is it possible to open multiple swipeable fragments with tabs when clicking in the navigation drawer?
- How do I make a "title" expandable/collapsible?
http://developer.android.com/design/patterns/navigation-drawer.html http://developer.android.com/training/implementing-navigation/nav-drawer.html
This is how I want the layout to be like:
title_section* not section_title ;)
Navigation Drawer is a new and trending design these days. We use two layouts: main content layout and the drawer list layout while designing the xml.layout(layout) for the navigation drawer activity. Here I'm answering all your silly questions.
simply add clicklistener on the drawer list items and replace fragments in the main content depending upon the position of the list item clicked.
Sample code:
Here f1, f2. f3 and f4 are different fragments each having its own layout. you have to create separate java classes for them by inheriting the fragment class.
In order implement tabs within a fragment you can use a tabhost inside that particular fragment. Suppose you want to add tabs in fragment f_main.
layout for F_main.xml
Then make other fragments f_tab1 and f_tab2 with their corresponding layouts and java classes. Layouts for the two tab fragments can be same or different. here I'm taking them same or a common layout.
Code for F_tab1.java fragment
Code for another fragment. i.e F_tab2.java
Now simply use clicklistener in the drawer list as mentioned earlier to load F_main on item click in the drawer list which will further load the tabs in the F_main fragmnet in the main content view.
Well I don't know wheather the NV drawer provides this feature or not. But it provides a feature to toggle the action bar title depending upon the drawer item selected or the main content fragment loaded.
As discussed in the Navigation Drawer design guide, you should modify the contents of the action bar when the drawer is visible, such as to change the title and remove action items that are contextual to the main content. The following code shows how you can do so by overriding DrawerLayout.DrawerListener callback methods with an instance of the ActionBarDrawerToggle class as follows