title: Sliding Drawer close on back button pressed
body: <p>I have a sliding drawer in my application.</p>
  
  <p>It open when I click on <code>android:handle</code>, which I have given to an image view.</p>
  
  <p>I want to close the drawer when back button is pressed.</p>
  
  <p>Code:</p>
  
  <pre><code>SlidingDrawer slider;
  
  @Override
  public void onBackPressed() { 
      slider.close ();
  }           
  super.onBackPressed();
  </code></pre>
  
  <p>Main. Xml file</p>
  
  <pre><code> &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:gravity="center"
  android:orientation="vertical" &gt;
  
  
  &lt;LinearLayout
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:gravity="right"
      android:orientation="vertical" &gt;
  
  &lt;SlidingDrawer
  android:id="@+id/slider"
  android:layout_width="150dp"
  android:layout_marginRight="0dp"
  android:layout_height="match_parent"
  android:handle="@+id/handle"
  android:content="@+id/content"
  
  android:orientation="horizontal"
  &gt;
  &lt;ImageView
      android:id="@+id/handle"
      android:background="@drawable/up"
      android:layout_width="50dp"
      android:layout_height="50dp"
      android:gravity="center"
      /&gt;
  &lt;GridView
      android:id="@+id/content"
      android:background="@color/black"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      /&gt;
  &lt;/SlidingDrawer&gt;
  &lt;/LinearLayout&gt;
  &lt;/RelativeLayout&gt;    
  </code></pre>
  
  <p>Activity file</p>
  
  <pre><code>@Override
  public void onCreate(Bundle savedInstanceState)
  {
      SlidingDrawer slide = (SlidingDrawer)this.findViewById(R.id.slider);
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  }
  
  
  @Override public void onBackPressed() { 
  if(slide.isOpened()){ 
  slide.close ();
  }
  else{
      super.onBackPressed(); 
      }
  
  }
  </code></pre>
  
  <p>}</p>