This question already has answers here:
Android - Is Navigation Drawer from right hand side possible?
(10 answers)
Closed 6 years ago.
I'm working on this project, and i need to create a double drawer app, it's possible to modify the navigation drawer so it can work both sides? or do I created a double drawer without using the navigation drawer.
try Sliding menu lib
SlidingMenu
You will have to implement the button feature yourself but it shouldn't be too hard!
EDIT:
An example:
SlidingMenu menuS = new SlidingMenu(this);
menuS.setMode(SlidingMenu.LEFT_RIGHT);
menuS.setMenu(R.layout.slideout_list);
menuS.setSecondaryMenu(R.layout.slideout_list2);
As the code shows you need to set the mode to LEFT_RIGHT and must specify a layout for both the left menu (setMenu()) and the right menu (setSecondaryMenu()) along with the other options specifying menu size and shadows etc.
If your navigation drawers needs to display different data (why would you display the same data from the right and the left?) like a navigation on the left and a search filter on the right. You'd better use 2 different drawers, each one with his own data / behaviour.
<android.support.v4.widget.DrawerLayout
android:id="#+id/drawer_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="#layout/content_main_activity"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_ad_list"
app:menu="#menu/activity_main_navigation_menu"
headerLayout="#layout/nav_header_ad_list"
menu="#menu/activity_main_navigation_menu"
tools:layout_gravity="start"
/>
<android.support.design.widget.NavigationView
android:id="#+id/activity_main_search_filter"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:layout_gravity="end"
tools:layout_gravity="end"
/>
</android.support.v4.widget.DrawerLayout>
You have to combine some of the methodology. like you have to implement fragment in that navigation view portion in navigation drawer layout. second there is no way both drawer can be opened at same time so implement one fragment over there and on the basis of different click event open drawer layout with different gravity value (GravityCompat.START, GravityCompat.END).
like from drawer button open drawer from left and from filter button open drawer from right and load different fragment view on the basis of that. I hope it will serve your purpose.
Related
I have been looking into DrawerLayout for my project's slideout menu. It seems to behave the way I want, except for one thing.
I've run a few sample projects and they all seem to have one thing in common: the DrawerLayout is always the main part of the application, as in:
setContentView(R.layout.activity_main);
Where activity_main is:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="#layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
Also, DrawerLayout seems to have strong ties to navigation, where it's used to jump between fragments.
My problem is, I do not wish to use this slideout menu for navigation, nor do I have any desire to make my app's current main page a Fragment. I want a slideout menu, but I will be using it for settings mostly, not to move around the app.
Is there any way to have a simple slideout menu, which behaves visually and tactically like DrawerLayout, but without the need to have all my views set as fragments of it?
I have recently done this using 1. a custom RelativeLayout class with a ViewTreeObserver referencing a custom X or Y property (for drawer you would use X) 2. objectAnimator XML referencing same custom property 3. Fragment class for the UI itself, using the custom Layout class 4. use setCustomAnimations method of getFragmentManager to show / hide the menu.
Here's an example, just change it to horizontal
Fragment Translation Animation for a Menu
by default half of hamburger is shown, as seen at the top left corner of the screenshot. I want to display full hamburger. code is taken from https://developer.android.com/training/implementing-navigation/nav-drawer.html. how can I do this?
Seems you are using very old technique to create Navigation Drawer. Its around 4 years old code and seems perfect regarding old version.
FYI, previously this kind of UI was done using DrawerLayout with ListView. But now android itself officially introduced sliding panel menu by introducing a newer concept called Navigation Drawer in which we combine DrawerLayout and NavigationView to achieve the desired output.
How to make hamburger menu fully visible?
SOLUTION:
Use AppCompatActivity instead of Activity and use AppCompat theme to achieve your desired output.
Use NavigationView instead of ListView.
Here is an example of NavigationView:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<!-- Your contents -->
<android.support.design.widget.NavigationView
android:id="#+id/navigation"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:menu="#menu/my_navigation_items" />
</android.support.v4.widget.DrawerLayout>
Here is a very good tutorial: Android Sliding Menu using Navigation Drawer
Hope this will help~
Requirement:- Action Bar Tabs using ViewPager with Navigation Drawer .
I can create a Navigation Drawer example
Action Bar Tabs using ViewPager separately.
But when I try to use both at once I am having issue.
I can create Navigation Drawer using fragments and Action Bar Tabs using Fragment. But the initial Activity of the both examples is Fragment Activity.
How to implement the action bar tabs on a fragment which is part of the navigation drawer?
The problem of using the tabs of the actionbar is when the drawer appears, it will appears under the tabs, since the tabs are part of the actionBar.
I have tried using tabHost instead and it works much better.
You get the source code here:
https://github.com/jiahaoliuliu/DrawerWithTabsAndViewPager
Here is a little explanation about it:
The first level there is a Drawer, from the v4 support library
Inside the drawer, the first element is the tabHost, which I have set the width and the height of the content to 0.
Under the tabhost, there is the viewpager.
Once everything has been created, what I have done is create a listener for the tabhost and another one for the viewPager, so when the user click on any tab the view pager will set the current item, and viceversa.
Enjoy Coding!
Use the following layout for your main activity.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.v4.view.ViewPager
android:id="#+id/viewpager_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffe6e1d4"
android:focusable="true"
android:focusableInTouchMode="true" />
<ListView
android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:listSelector="#drawable/drawer_list_selector"
android:background="#color/drawer_bg" />
</android.support.v4.widget.DrawerLayout>
Write your FragmentPagerAdapter as show in APPTabsAdapter.
This is how I had built it in one of my projects.
You can try and ask for help, if needed.
OR
You can take help from this GitHub Repo.
Thanks.
As you have noticed, ActionBar tabs don't play very nicely with Navigation Drawer and this design mode has been deprecated in API 21 anyway.
I used the classes in SlidingTabs example from Android developers to achieve this effect without having to include a 3rd party library dependency, and am very happy with the result. There is a video tutorial as well.
I'd like to create an extra-information view similar to that of the Google Drive app (below) on a tablet. When the info button is clicked, this view slides in from the rightcontaining a layout. Another example would be the Google+ app with its notifications slide-out panel:. The SlidingLayer by 6Wunderkinder almost works, but doesn't fade a semi-black background over the views behind the "drawer" and I haven't found another library that does this.
If anybody has any suggestions/solutions please let me know!
Also, I've already looked at this question and none of the answers suggested there are correct either.
For posterity, here's the answer to this question. As Steve Benett's suggestion led me to discover, the correct way to do this is to use two DrawerLayouts, nested within each other like so:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_navigation_bar"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.DrawerLayout
android:id="#+id/drawer_sidebar"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="#+id/fragment_main_content"
android:name="MainContentFragment"
android:layout_height="match_parent"
android:layout_width="match_parent" />
<fragment
android:id="#+id/fragment_sidebar"
android:name="SidebarFragment"
android:layout_width="300dp"
android:layout_height="match_parent"
android:layout_gravity="end" />
</android.support.v4.widget.DrawerLayout>
<fragment
android:id="#+id/fragment_navigation_bar"
android:name="NavigationFragment"
android:layout_height="match_parent"
android:layout_width="300dp"
android:layout_gravity="start" />
</android.support.v4.widget.DrawerLayout>
The innermost DrawerLayout contains the main content of the Activity, whether it be a fragment or some other layout components. fragment_sidebar is the fragment that will be swiped out from the right. Then, on the top-level DrawerLayout you have the fragment_nagivation_bar which houses the left Drawer's ListView or whatever.
Then, in the Activity Java code you have:
mDrawerLayoutLeft= (DrawerLayout) findViewById(R.id.drawer_navigation_bar);
mDrawerLayoutRight = (DrawerLayout) findViewById(R.id.drawer_sidebar);
mDrawerLayoutLeft.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
mDrawerLayoutRight.setDrawerShadow(R.drawable.sidebar_shadow, GravityCompat.END);
An optional addition (but recommended, for consistency of UX) is to hide the other Drawer when one is opened, so your screen doesn't consist solely of Drawers.
I hope this has helped somebody!
This is the DrawerLayout. Have a look at the design guide, which illustrates the behavior well.
If you want to use / customize the "semi-black background" use DrawerLayout.setDrawerShadow() with a drawable. Google hands out a set of drawables here. Download the ActionBar Icon Pack and look for the drawable_shadow.9.png.
If you want that the menu appears from the right, set android:layout_gravity="end" as a property in the second child of the layout.
I would like to know what is the type of Android Activity implemented in the image where you can put for example configurations and hide it with a swipe gesture
It is Navigation Drawer a panel that transitions in from the left edge of the screen and displays the app’s main navigation options.
You can find how to Create a Navigation Drawer here
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- The navigation drawer -->
<ListView android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:background="#111"/>
</android.support.v4.widget.DrawerLayout>
The drawer view (the ListView) must specify its horizontal gravity with the android:layout_gravity attribute. To support right-to-left (RTL) languages, specify the value with "start" instead of "left" (so the drawer appears on the right when the layout is RTL).
It looks like Navigation Drawer ,The Navigation Drawer is a panel that transitions in from the left edge of the screen and displays the app’s main navigation options.
for more information you can visit developer Link
Following are the GitHub links where you can find Navigation Drawer source code
Navigation Drawer Source Code Link 1
Navigation Drawer Source Code Link2
Navigation Drawer Source Code Link 3
Navigation Drawer Source Code Link 4
More Collection
That is referred to either as a sliding menu or a navigation drawer.
Google released their own implementation for this last week: http://developer.android.com/training/implementing-navigation/nav-drawer.html
The most popular implementation prior to that was probably this SlidingMenu component.