Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Building upon CommonsWare's answer you can do this with a couple of adjustments. The first is setting the following three lines:</p> <pre><code>drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN); drawerLayout.setScrimColor(getResources().getColor(R.color.drawerNoShadow)); isDrawerLocked = true; </code></pre> <p>The drawerNoShadow color can just be a no-alpha color (like 0x00000000). That gets you an open drawer with no background overlay.</p> <p>The second thing you need to do is adjust the padding_left value of your FrameLayout. For this purpose you can setup a dimension to control this (0dp by default) - in this example R.dimen.drawerContentPadding. You will also need an R.dimen.drawerSize value that will be the width of the DrawerLayout.</p> <p>This allows you to check the paddingLeft value of the FrameLayout to call those lines.</p> <pre><code>FrameLayout frameLayout = (FrameLayout)findViewById(R.id.content_frame); if(frameLayout.getPaddingLeft() == (int)getResources().getDimension(R.dimen.drawerSize) { drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN); drawerLayout.setScrimColor(getResources().getColor(R.color.drawerNoShadow)); isDrawerLocked = true; } </code></pre> <p>You can then wrap all the functionality you don't want to enable in an <code>if(!isDrawerLocked)</code> statement. This will include:</p> <ul> <li><code>drawerLayout.setDrawerListener(drawerToggle);</code></li> <li><code>getActionBar().setDisplayHomeAsUpEnabled(true);</code></li> </ul> <p>Lastly you do need to setup alternate layouts for the views with a static drawer. An example is:</p> <pre><code>&lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"&gt; &lt;android.support.v4.widget.DrawerLayout android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent"&gt; &lt;!-- The navigation drawer --&gt; &lt;ListView android:id="@+id/left_drawer" android:layout_width="@dimen/drawerSize" android:layout_height="match_parent" android:layout_gravity="start" android:choiceMode="singleChoice" android:divider="@android:color/transparent" android:dividerHeight="0dp" android:background="#111"/&gt; &lt;/android.support.v4.widget.DrawerLayout&gt; &lt;FrameLayout android:id="@+id/content_frame" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginLeft="@dimen/drawerContentPadding"/&gt; </code></pre> <p></p> <p>The beauty here is you can then control all of the logic by setting up alternate dimen.xml files for the devices you want to target and the only thing you need to change is the value of drawerContentPadding and offer the modified layouts.</p> <p><em>NOTE:</em> I ended up using margin_left instead of padding_left since in the new layout it overlays the drawer. See a more in-depth blog post about the technique at <a href="http://derekrwoods.com/2013/09/creating-a-static-navigation-drawer-in-android/">http://derekrwoods.com/2013/09/creating-a-static-navigation-drawer-in-android/</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload