title: Android changing the width of the navigation drawer panel programmatically
body: <p>I've used the Navigation Drawer template presents in Android Studio.
  In the layout of my activity I have this following code:</p>
  
  <pre><code>&lt;fragment android:id="@+id/navigation_drawer"
      android:layout_width="@dimen/navigation_drawer_width"
      android:layout_height="match_parent"
      android:layout_gravity="start"
      android:name="com.smedilepaolo.newsfeed.NavigationDrawer.NavigationDrawerFragment"
      tools:layout="@layout/fragment_navigation_drawer" /&gt;
  </code></pre>
  
  <p>What I need is to change programmatically the width of the panel.
  I think that the right zone to change it is this:</p>
  
  <pre><code>    @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_news_feed);
  
          mNavigationDrawerFragment = (NavigationDrawerFragment)
                  getFragmentManager().findFragmentById(R.id.navigation_drawer);
          mTitle = getTitle();
  
  ....
  </code></pre>
  
  <p>But I can't understand how can achieve my target. </p>
  
  <p>/<strong>* UPDATE *</strong>/</p>
  
  <p>The icon of the drawer panel is not showed in the action bar</p>
  
  <pre><code>    mDrawerListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
              mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
  
              mDrawerListView.post(new Runnable() {
                  @Override
                  public void run() {
                      Resources resources = getResources();
                      float width = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 240, resources.getDisplayMetrics());
                      DrawerLayout.LayoutParams params = (DrawerLayout.LayoutParams) mDrawerListView.getLayoutParams();
                      params.width = (int) (width);
                      mDrawerListView.setLayoutParams(params);
  
                  }
              });
  
              selectItem(position);
          }
      });
  
  
  
      mDrawerListView.post(new Runnable() {
          @Override
          public void run() {
              Resources resources = getResources();
              float width = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, resources.getDisplayMetrics().widthPixels-1, resources.getDisplayMetrics());
              DrawerLayout.LayoutParams params = (DrawerLayout.LayoutParams) mDrawerListView.getLayoutParams();
              params.width = (int) (width);
              mDrawerListView.setLayoutParams(params);
              mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
              mDrawerLayout.openDrawer(mFragmentContainerView);
          }
      });
  </code></pre>
  
  <p>That's the selectItem method</p>
  
  <pre><code>    private void selectItem(int position) {
          mCurrentSelectedPosition = position;
          if (mDrawerListView != null) {
              mDrawerListView.setItemChecked(position, true);
          }
          if (mDrawerLayout != null) {
              mDrawerLayout.closeDrawer(mFragmentContainerView);
          }
  
  ....
  </code></pre>