Set drag margin for Android Navigation Drawer

Here I’ve found a solution via reflections DrawerLayout mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); Field mDragger = mDrawerLayout.getClass().getDeclaredField( “mLeftDragger”);//mRightDragger for right obviously mDragger.setAccessible(true); ViewDragHelper draggerObj = (ViewDragHelper) mDragger .get(mDrawerLayout); Field mEdgeSize = draggerObj.getClass().getDeclaredField( “mEdgeSize”); mEdgeSize.setAccessible(true); int edge = mEdgeSize.getInt(draggerObj); mEdgeSize.setInt(draggerObj, edge * 5); //optimal value as for me, you may set any constant in dp

Switch between Fragments with onNavigationItemSelected in new Navigation Drawer Activity template (Android Studio 1.4 onward)

So, based on @L.L.’s answer I was able to solve this problem. First of all, add your FrameLayout to your content_main.xml file: <FrameLayout android:layout_width=”match_parent” android:layout_height=”match_parent” android:id=”@+id/content_frame”/> In your MainActivity (or whatever you have named the Activity with the navigation drawer) define a method named displayView public void displayView(int viewId) { Fragment fragment = null; String … Read more

How can I change the NavigationView’s item text size?

Create new style at the file app/src/main/res/values/styles.xml <style name=”NavigationDrawerStyle”> <item name=”android:textSize”>20sp</item><!– text size in menu–> <!– item size in menu–> <item name=”android:listPreferredItemHeightSmall”>40dp</item> <item name=”listPreferredItemHeightSmall”>40dp</item> <!– item padding left in menu–> <item name=”android:listPreferredItemPaddingLeft”>8dp</item> <item name=”listPreferredItemPaddingLeft”>8dp</item> <!– item padding right in menu–> <item name=”android:listPreferredItemPaddingRight”>8dp</item> <item name=”listPreferredItemPaddingRight”>8dp</item> </style> Add it to your main_layout.xml <android.support.design.widget.NavigationView … app:theme=”@style/NavigationDrawerStyle” ….> </android.support.design.widget.NavigationView> … Read more

Android – Navigation View item menu background color

You don’t set the drawable for the background of a Navigation View item in your styles.xml file. Open up your XML layout file containing your Navigation View widget, and add the following line to the widget’s attributes: app:itemBackground=”@drawable/activated_background.xml” If you’re having trouble with the “app” pointer, add the following line in as well: xmlns:app=”http://schemas.android.com/apk/res-auto” Note … Read more

Navigation Drawer with backword compatibility android

You need to use appcompact from the Support Library. Your activity needs to extend ActionBarActivity. In your Activity public class MainActivity extends ActionBarActivity { Import import android.support.v7.app.ActionBarActivity; Instead of getActionBar() use getSupportActionbar() Use Them.AppCompact Or use ActionBarSherlock library. https://stackoverflow.com/questions/20071004/add-icon-in-drawerlist-by-actionbarsherlock/20077469#20077469 Example: MainActivity.java public class MainActivity extends ActionBarActivity { // Fields —————————————————————– private DrawerLayout drawerLayout; private ListView … Read more

How do I make DrawerLayout to display below the Toolbar?

<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:app=”http://schemas.android.com/apk/res-auto” android:orientation=”vertical” android:layout_width=”match_parent” android:layout_height=”match_parent”> <!– The toolbar –> <android.support.v7.widget.Toolbar android:id=”@+id/my_awesome_toolbar” android:layout_height=”wrap_content” android:layout_width=”match_parent” android:minHeight=”?attr/actionBarSize” android:background=”?attr/colorPrimary” /> <android.support.v4.widget.DrawerLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:id=”@+id/my_drawer_layout” android:layout_width=”match_parent” android:layout_height=”match_parent”> <!– drawer view –> <LinearLayout android:layout_width=”304dp” android:layout_height=”match_parent” android:layout_gravity=”left|start”> <!– drawer content –> </LinearLayout> <!– normal content view –> <LinearLayout android:layout_width=”match_parent” android:layout_height=”match_parent” android:orientation=”vertical”> <!– The rest of content view –> </LinearLayout> </android.support.v4.widget.DrawerLayout> </LinearLayout>

Navigation Drawer: set as always opened on tablets

Based on the idea of larger devices could have different layout files, I have created the follow project. https://github.com/jiahaoliuliu/ABSherlockSlides HighLights: Since the drawer of a large device is always visible, there is not need to have an drawer. Instead, a LinearLayout with two elements with the same name will be enough. <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”match_parent” android:layout_height=”match_parent” … Read more