2014-04-03 118 views

回答

1

假設您通過ListView執行Navigation Drawer,您需要通過添加ImageView來修改列表項目的佈局。然後,您應該修改用於填充ListView的適配器,以便相應地設置的。

引用手冊中您鏈接:

// Set the adapter for the list view 
    mDrawerList.setAdapter(new ArrayAdapter<String>(this, 
      R.layout.drawer_list_item, mPlanetTitles)); 

這是大多數的更改將有線:指定包含一個TextView並和ImageView的佈局,並創建一個新的適配器。

爲了方便起見,您可以創建一個名爲類似NavDrawerItem的類,它將包含兩個字段:一個用於圖標,另一個用於通過TextView顯示的標題。

在您的適配器中,請務必考慮您不會顯示圖標的菜單項。

0

試試這個

private ActionBarDrawerToggle mDrawerToggle; 
mDrawerToggle=new ActionBarDrawerToggle(this, 
      mdrawerlayout, 
      R.drawable.ic_whats_hot, 
      R.string.app_name, 
      R.string.app_name) 
    { 
     public void onDrawerClosed(View view) 
     { 
      getActionBar().setTitle(mTitle); 
      invalidateOptionsMenu(); 
     } 
     public void onDrawerOpened(View view) 
     { 
      getActionBar().setTitle(R.string.app_name); 
      invalidateOptionsMenu(); 
     } 
    }; 
public boolean onOptionsItemSelected(MenuItem item) 
{ 
    if(mDrawerToggle.onOptionsItemSelected(item)) 
    { 
     return true; 
    } 
    switch(item.getItemId()) 
    { 
     case R.id.action_settings: 

      intent1=new Intent(MainActivity.this,ActivitySetting.class); 

      startActivity(intent1); 
      return true; 
     case R.id.action_websearch: 

      intent1=new Intent(Intent.ACTION_VIEW,Uri.parse("http://http://www.vogella.com/")); 
      startActivity(intent1); 
      return true; 

     default : 

      return super.onOptionsItemSelected(item); 
    } 
} 

在編碼和XML文件

<menu xmlns:android="http://schemas.android.com/apk/res/android"> 

<item 
    android:id="@+id/action_websearch" 
    android:showAsAction="always" 
    android:icon="@drawable/action_search" 
    android:title="search"/> 
<item 
    android:id="@+id/action_settings" 
    android:title="Settings" 
    android:icon="@drawable/ic_launcher" 

    > 
</item> 
<item 
    android:id="@+id/action_logout" 
    android:title="logout" 
    android:icon="@drawable/ic_launcher" 

    /> 

試試這個