Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Navigation Drawer over the tabs

I am using the new navigation drawer available from the support library. When using the drawer along with tabs, the drawer menu is getting displayed below the tabs as shown below. How can i make sure the drawer menu is shown on the tabs. (It should display the drawer menu as if there are no tabs)

Drawer menu without tabs enter image description here

Drawer menu with tabs

enter image description here

like image 237
suresh cheemalamudi Avatar asked May 23 '13 12:05

suresh cheemalamudi


People also ask

How do I customize my navigation drawer?

Android App Development for BeginnersStep 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml. Step 3 − Add the following code to res/layout/nav_header_main.

How do I get navigation drawer in all activity?

The user can view the navigation drawer when they swipe the activity's screen from the left edge of the android device. A user can also find it from the activity, by tapping the app icon (also known as the “hamburger” menu) in the action bar.


2 Answers

I got the same issue and the answer I got from Roman Nurik (Android team) is that the Navigation Drawer should not be used with the Action Bar tabs.

The discussion can be found here: https://plus.google.com/u/1/116515063230772720916/posts/8dWEkFcbTFX

like image 199
David TA Avatar answered Oct 14 '22 12:10

David TA


Create a separate fragment say TabsFragment and add the fragment inside the fragment container in your main activity.

The tabs can be added inside the tabs fragment with the following code.

private FragmentTabHost mTabHost;  @Override public View onCreateView(LayoutInflater inflater, ViewGroup container,         Bundle savedInstanceState) {     mTabHost = new FragmentTabHost(getActivity());     mTabHost.setup(getActivity(), getChildFragmentManager(), R.id.fragment1);      mTabHost.addTab(mTabHost.newTabSpec("TabA").setIndicator("TabA"),            TabA.class, null);     mTabHost.addTab(mTabHost.newTabSpec("TabB").setIndicator("TabB"),             TabB.class, null);      return mTabHost; } 

Here, TabA and TabB are separate fragments for the tabs. You can implement your functionality of the respective tabs in respective fragments. Reference : http://developer.android.com/reference/android/support/v4/app/FragmentTabHost.html

like image 31
andinrajesh Avatar answered Oct 14 '22 11:10

andinrajesh