iOS-like Navigation Drawer for Android? - android

I'm looking for a way to reproduce the navigation drawer of iOS on Android.
I can't figured out how to reproduce it.
The Navigation Drawer on iOS slide all the previous page and keep a little part of it on screen like this:
iOS like Navigation Drawer
Meanwhile the android Navigation Drawer goes over the previous page and hide it like this:
Android like Navigation Drawer
Is it just possible ?

Affirmative, it's very much possible in Android. Add the following in your build.gradle file:
dependencies {
implementation 'com.infideap.drawerbehavior:drawer-behavior:0.2.2'
}
Use android.support.design.widget.NavigationView inside your layout with com.infideap.drawerbehavior.AdvanceDrawerLayout to achieve this type of behavior like this:
<com.infideap.drawerbehavior.AdvanceDrawerLayout 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"
android:background="#color/colorWhite"
tools:openDrawer="start">
<include
layout="#layout/app_bar_default"
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"
android:background="#color/colorWhite"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer" />
</com.infideap.drawerbehavior.AdvanceDrawerLayout>
For more on the implementations & sample demos, please follow this link. Hope this helps!

iOS doesn't have a build-in Navigation Drawer component. The first link you provided contains a custom implementation. Best possible is to use third-party solution. For example, quite popular is SideMenu.

Related

Using Scrolling Activity inside Navigation Activity

my primary goal is to have a navigation drawer with a Scrolling Activity while implementing material design so it would look something like a combination of these two:
Navigation Drawer Sample Image (Credits to Google)
Scrolling Activity Sample Image (Credits to Google)
As of right now I am doing this by associating a Navigation Drawer Layout's xml to my main activity and then including a Scrolling Layout's xml inside of Navigation Drawer Layout's content xml.
It's working after implementing many small changes in xmls of both the layouts but I don't feel like it's the optimal way to do so as it results in using more than 7 xmls at once for only one activity.
Does anybody know of a better way to do so?
You have to include scrolling layout into navigation layout.
<?xml version="1.0" encoding="utf-8"?>
<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">
<include layout="#layout/activity_scrolling"/>
<android.support.design.widget.NavigationView
android:id="#+id/navigation_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>

How to make the second navigation drawer NOT cover the app bar?

I've been dealing with this DrawerLayout and NavigationViews and I don't seem to ba able to solve this issue. According to google guidelines the first navbar should cover the app bar and the second one should NOT.
How I achieve that? Whatever I do it either makes both of them cover or both of them not cover the app bar.
Since navigation view is pretty new I could not get any suitable answer googling and exploring overflow.com. Any guide, help, tutorial, sample... is highly appreciated.
Thanks before.
Here is my activity.xml
<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">
<!-- As the main content view, the view below consumes the entire
space available using match_parent in both dimensions. -->
<LinearLayout
android:orientation="vertical"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<include
android:id="#+id/app_bar"
layout="#layout/app_bar">
</include>
</LinearLayout>
<android.support.design.widget.NavigationView
android:id="#+id/nav_draw"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="#layout/drawer_header"
app:menu="#menu/drawer"/>
<android.support.design.widget.NavigationView
android:id="#+id/second_nav_draw"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="end"
/>
</android.support.v4.widget.DrawerLayout>
I don't know about NavigationView, but with other views a simple margin used to work. Try:
android:layout_marginTop="?attr/actionBarSize"

Using activity with drawer, scrolling toolbar, tabs and different fragments

I'm looking for best practices when it comes to the following pretty common setup:
What I'm currently doing is:
My Main Activity has a navigation drawer and a Toolbar.
When you click on one of the list items inside the drawer a fragment is loaded under the toolbar. Some fragments have their own tabs inside using viewpager ect.
I would like to make use of the material functionalities like hiding the toolbar while scrolling ect. It is no problem to get it done.
But there is a problem when only some of your fragments would like to make use of the scrolling toolbar. Using a normal Scrollview does solve the problem if you can add an additional margin at the bottom, but once you have a keyboard it will mess up as the scroll is wrong. Using a nestedscrollview works but does scroll the toolbar.
So how can I avoid the scrolling toolbar when my activity holds the toolbar and some fragments that scroll should make use of it and some not?
Is the architectural design wrong? Another thing I thought is to have the different toolbars inside of each fragment... but they have to share the same navigation drawer so you have to create and add the ToggleButton each time? Is it the right approach ? Should I go that path? I'm not convinced and would like to have the opinion of somebody more experienced then me. What's the best solution in this case.
Appreciate your help!
Cheers
EDIT:
Main Activity
<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">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/fragment_container_first"
>
<android.support.design.widget.AppBarLayout
android:id="#+id/appBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:id="#+id/owner_main_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/appBar"
android:orientation="horizontal"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/fab_margin"
android:src="#drawable/addicon"
app:fabSize="normal"
app:layout_anchor="#id/owner_main_container"
app:layout_anchorGravity="bottom|right|end"
app:layout_behavior="xxx.Classes.Misc.ScrollAwareFABBehavior"
/>
</android.support.design.widget.CoordinatorLayout>
<!-- The navigation drawer -->
<android.support.design.widget.NavigationView
android:id="#+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:menu="#menu/drawerhost" />
I am also Using navigation drawer and tool bar please import project from this link
And try to understand how to use navigation drawer and tool bar using fragment

Creating a custom widget with other widgets included

I am fairly new to android development and I am having a hard time figuring out the simplest way to create reusable code. I have found quite a few articles on google, android has a lot of parts and solutions I am having trouble seeing the pros and cons, so I will just post what I would like to do, then see what pops up.
Currently I have:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<RelativeLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="#+id/toolbar"
layout="#layout/widget_toolbar"/>
<ListView
android:background="#color/amber_A700"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/toolbar">
</ListView>
</RelativeLayout>
<apps.new.app.ui.widget.ScrimInsetsFrameLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/linearLayout"
android:layout_width="#dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#ffffffff"
android:fitsSystemWindows="true"
app:insetForeground="#4000" >
<fragment android:id="#+id/navigation_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.example.newapp.NavigationDrawerFragment"
tools:layout="#layout/frag_nav_drawer" />
</apps.new.app.ui.widget.ScrimInsetsFrameLayout>
</android.support.v4.widget.DrawerLayout>
Essentially what I want is to make this a library in which I could use in any project I want with a more simplistic style:
<android.my.custom.widget
...
app:drawerFragment="drawer_fragment_name"
...>
//Listview would go here
</android.my.custom.widget>
This would allow me to set the drawer fragment, include the "ScrimInsetsFrameLayout" automatically, include the toolbar automatically. Essentially I want a reusable library in which I could update and it would push to any app I use it in. What is the best practice with android dev? If this is simply a custom widget, how would I go about including other widgets in it and inserting fragments in them?
ultimately this would allow me to simplify the code a bunch and only see what is for this activity instead of seeing a bunch of boiler-plate code for the navigation drawer, RelativeLayout and toolbar.
I feel like I am just missing something obvious.
You need to create new class which inherits from DrawerLayout, inflate your views, set params.
Tutorial is here

Can I preview an open Navigation Drawer in Android Studio

I am making an app that will feature a Navigation Drawer. My computer cannot run the AVD emulator. Even with a minimal AVD, I have waited hours and it did not start up. That being said, I have had to rely on the Android Studio designer to see what the app will look like. When creating a Navigation Drawer activity, is there some way I can toggle it being open on the designer?
I found that you can add tools:openDrawer="start" to your DrawerLayout.
Like this:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout android:id="#+id/drawer"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:openDrawer="start">
<!-- your content include -->
<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:menu="#menu/drawer"/>
</android.support.v4.widget.DrawerLayout>
Demo:
not really perfect, but it's enough!

Categories

Resources