Action Bar Tabs using ViewPager with Navigation Drawer - android

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.

Related

how to make hamburger menu fully visible

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~

Put ViewPager in fragment of a menu drawer Android

I searched a solution everywhere but I didnt find anything, so I need one more time your help.
I have a Navigation drawer who works perfectly
Navigation drawer
I have also a ViewPager, that I have take on the Android developer's website. It works fine also.
Now I would like to put the PageViewer in my "jour" tab for exemple. But the PageViewer is not a "Fragment" but a "ActivityFragment" so I cannot. The help that I can find on the other threads does'nt match to my problem
How Can I do this ?
Thanks a lot for reading me.
Annex:
Tutorial Android : https://developer.android.com/training/animation/screen-slide.html
I dont know if i should create a new thread or not. I have put the code in the main activity but the fragment cover all the activity. screen of the fragment
It is strange because the other fragments work.
main Activity
TestSlideFragment fragment = new TestSlideFragment();
fragmentTransaction.replace(R.id.RelativeLayout_for_Fragment, fragment);
fragmentTransaction.commit();
layout of the fragment
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="oytoch.iut_info.test.TestSlideFragment">
<!-- TODO: Update blank fragment layout -->
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/page"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Open your Jour's xml and add the ViewPager Tag.
Then open Jour's java and bind an object of ViewPager with the xml. Add the adapter to the viewpager object and you are done.

Double Drawer in android [duplicate]

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.

Navigation Drawer Notification Icon without Actionbar

In my application I do not want to use the actionbar or toolbar as my app is fairly simplistic and having one of those two would clutter my application. I know when using an actionbar with a navigation drawer there is an icon on the top left to show the drawer exists; however, I want a small notification icon in the middle of the screen to show that the drawer exists. Perhaps a clear arrow? Is this possible? I can not find any documentation on how I would approach doing this. Thank you.
Edit:
I do not want to use ANY type of action bar
Update 2
You can wrap your indicator in a RelativeLayout.
<RelativeLayout android:layout_width="match_parent"
android:layout_width="match_parent"/>
<MyIndicator
android:id="#+id/indicator"
android:layout_width="match_parent"
android:layout_width="match_parent"
android:layout_centerVertical="true"
android:layout_alignParentStart="true"/>
<OtherView android:layout_width="match_parent"
android:layout_width="match_parent"/>
</RelativeLayout>
Update
Use FloatingActionButton from design library.
If you use a toolbar you can set a custom icon. Here is another post doing something like that: Custom icon in Android toolbar
You can use custom action bar in your app that can be customized according to your need.
Refer this link Custom Action Bar

Android NavigationDrawer and ViewPager as its one of fragment

I have created a SherlockFragmentActivity that has three fragments for ViewPager. But now I want to use this Activity in NavigationDrawer but I am confused how to do this. Google+ app has this kind of implementation but I am wondering about how to achieve this.
NavigationDrawer will have following UI elements:
FragmentActivity(contains three fragment as ViewPager)
Second Fragment
Third Fragment
Is this kind of layout possible with Navigation Drawer If yes, how should I do it. If not, what should I do to achieve this kind of navigation in my app.
It is very much possible. You just have to create the right layout file for it.
<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 -->
<RelativeLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- viewpager goes here -->
</RelativeLayout>
<!-- The navigation drawer -->
<LinearLayout android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_gravity="start">
<!-- fragment one goes here in drawer -->
<!--- fragment two goes here in drawer-->
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
A DrawerLayout has to have 2 childs, the first is the main content, in your case this will contain the ViewPager and perhaps other stuff. The second child is the Drawer itself.
Use this as the content of your activity.
The rest of the information can be found by using the example on the android developers page here
You can use below libraries to get navigation model similar to your requirement
ActionBarSherlock (github)
nested-fragments (github)
PagerSlidingTabStrip (github)
NavigationDrawer (Android developer site)
Latest Support v4 library
Have a look at my post
Below is screenshot of my sample app Navigation Drawer with Tab Strip Example at github

Categories

Resources