Navigation Drawer (Google+ vs. YouTube)
Edit #3:
The Navigation Drawer pattern is officially described in the Android documentation!
Check out the following links:
- Design docs can be found here.
- Developer docs can be found here.
Edit #2:
Roman Nurik (an Android design engineer at Google) has confirmed that the recommended behavior is to not move the Action Bar when opening the drawer (like the YouTube app). See this Google+ post.
Edit #1:
I answered this question a while ago, but I'm back to re-emphasize that Prixing has the best fly-out menu out there... by far. It's absolutely beautiful, perfectly smooth, and it puts Facebook, Google+, and YouTube to shame. EverNote is pretty good too... but still not as perfect as Prixing. Check out this series of posts on how the flyout menu was implemented (from none other than the head developer at Prixing himself!).
Original Answer:
Adam Powell and Richard Fulcher talk about this at 49:47 - 52:50 in the Google I/O talk titled "Navigation in Android".
To summarize their answer, as of the date of this posting the slide out navigation menu is not officially part of the Android application design standard. As you have probably discovered, there's currently no native support for this feature, but there was talk about making this an addition to an upcoming revision of the support package.
With regards to the YouTube and G+ apps, it does seem odd that they behave differently. My best guess is that the reason the YouTube app fixes the position of the action bar is,
One of the most important navigational options for users using the YouTube app is search, which is performed in the
SearchView
in the action bar. It would make sense to make the action bar static in this regard, since it would allow the user to always have the option to search for new videos.The G+ app uses a
ViewPager
to display its content, so making the pull out menu specific to the layout content (i.e. everything under the action bar) wouldn't make much sense. Swiping is supposed to provide a means of navigating between pages, not a means of global navigation. This might be why they decided to do it differently in the G+ app than they did in the YouTube app.On another note, check out the Google Play app for another version of the "pull out menu" (when you are at the left most page, swipe left and a pull out, "half-page" menu will appear).
You're right in that this isn't very consistent behavior, but it doesn't seem like there is a 100% consensus within the Android team on how this behavior should be implemented yet. I wouldn't be surprised if in the future the apps are updated so that the navigation in both apps are identical (they seemed very keen on making navigation consistent across all Google-made apps in the talk).
mimicking the navigation drawer of youtube/gmail app
Use this MenuDrawer
A slide-out menu implementation, which allows users to navigate between views in your app.
Features:
- The menu can be positioned along all four edges.
- Supports attaching an always visible, non-draggable menu, which is useful on tablets.
- The menu can wrap both the content and the entire window.
- Allows the drawer to be opened by dragging the edge, the entire screen or not at all.
- Can be used in XML layouts.
- Indicator that shows which screen is currently visible
Make Custom Navigation drawer like You-Tube in android
Yesterday I faced same problem
but this examples highlight selector in whole listbackground but i also want red color indicator at starting which is mention
You need to create two selector. 1. For whole item 2. for that red part
For that Place a view in listitem on left side and create a selector for it.
then use following code. Here android:duplicateParentState="true"
works for you.
When this attribute is set to true, the view gets its drawable state
(focused, pressed, etc.) from its direct parent rather than from
itself.
<TextView
android:layout_width="3dp"
android:layout_height="match_parent"
android:duplicateParentState="true"
android:background="@drawable/selector_for_red" />
Navigation Drawer item Click not Works.followed Questions
Check this answer:
search_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical">
<androidx.drawerlayout.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="false"
tools:openDrawer="start">
<include
layout="@layout/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.google.android.material.navigation.NavigationView
android:id="@+id/nav_view"
android:layout_width="@dimen/_240sdp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/white_color"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_drawer"
app:menu="@menu/drawer_menu"/>
</androidx.drawerlayout.widget.DrawerLayout>
</LinearLayout>
SearchActivity.java
public class SearchActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener{
DrawerLayout drawer;
NavigationView navigationView;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.search_activity);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle("Home");
toolbar.setTitleTextColor(getResources().getColor(android.R.color.white));
drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
navigationView = (NavigationView) findViewById(R.id.nav_view);
View hView = navigationView.getHeaderView(0);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
toggle.syncState();
toggle.getDrawerArrowDrawable().setColor(getResources().getColor(R.color.white_color));
navigationView.setNavigationItemSelectedListener(this);
navigationView.setItemIconTintList(null);
}
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
switch (menuItem.getItemId()) {
case R.id.nav_home:
Intent home = new Intent(SearchActivity.this, Your_Acivity.class); //here place your Activity Class
startActivity(home);
break;
case R.id.nav_car_info:
Intent car_info = new Intent(SearchActivity.this,Your_Activity.class); //here place your Activity Class
startActivity(car_info);
break;
}
return false;
}
}
Related Topics
How to Install Android Sdk Build Tools on the Command Line
Google Cloud Endpoints and User's Authentication
Android - File Provider - Permission Denial
Bluetooth Low Energy Startscan on Android 6.0 Does Not Find Devices
Install an APK File from Command Prompt
Install_Failed_Duplicate_Permission... C2D_Message
Android Getlastknownlocation Returns Null
Android/Webkit Text-Overflow: Ellipsis Not Working
How to Check the Internet Connection in Android
Generate APK File from Aab File (Android App Bundle)
Why Is Android Studio Reporting "Uri Is Not Registered"
How to Make an Application Ignore Screen Orientation Change
Android Studio Fails to Debug with Error Org.Gradle.Process.Internal.Execexception
Use Uri Builder in Android or Create Url with Variables
Android Webview Style Background-Color:Transparent Ignored on Android 2.2
Failed to Resolve: Com.Android.Support:Appcompat-V7:27.+ (Dependency Error)