2016-07-10 59 views
0

我正在關注Android教程,該教程建議使用V4 Navigation Drawer,它應該在左側給我一個漢堡包導航圖標。 反而會發生什麼,如果我用一個圖標我有這樣的結果:導航抽屜圖標(用GIMP製作)需要太多空間

icon made with Gimp

相反,如果我用另一個類似圖標它更是雪上加霜,佔據所有空間: similar icon different behaviour

我不明白:

1)如何使用第二個圖標一種方式在左側,而其他圖標繼續出現,就像人們對導航抽屜的期望一樣?

2)爲什麼是兩個不同的圖標有這樣的不同的行爲,畢竟我曾將它們與瘸子給他們200x200像素尺寸

我的主類:

import android.support.v4.app.ActionBarDrawerToggle; 
import android.support.v4.widget.DrawerLayout; 

public class MainActivity extends Activity{ 

@Override 
protected void onCreate(Bundle savedInstanceState) { 

getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY); 
getActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#00000000"))); 
getActionBar().setStackedBackgroundDrawable(new ColorDrawable(Color.parseColor("#550000ff"))); 

    super.onCreate(savedInstanceState); 


     setContentView(R.layout.activity_main);  
String[] provaListaDrawer = {"List1", "List2", "List3"}; 
     mTitle = mDrawerTitle = getTitle(); 

     DrawerLayout mDrawerLayout = 
       (DrawerLayout) findViewById(R.id.drawer_layout); 
     actionBarDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.app_drawer, R.string.drawer_open, R.string.drawer_close) 

     { 

      /** 
      * Called when a drawer has settled in a completely closed state. 
      */ 
      public void onDrawerClosed(View view) { 
       super.onDrawerClosed(view); 
       getActionBar().setTitle(mTitle); 
       Log.d("IVO", "onDrawerClosed"); 
       invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() 
      } 

      /** 
      * Called when a drawer has settled in a completely open state. 
      */ 
      public void onDrawerOpened(View drawerView) { 
       super.onDrawerOpened(drawerView); 
       getActionBar().setTitle(mDrawerTitle); 
       Log.d("IVO", "onDrawerOpened"); 

       invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() 
      } 
     } 
     ; 

     ListView mDrawerList = (ListView) findViewById(R.id.left_drawer); 

    mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_view,provaListaDrawer)); 

     mDrawerList.setOnItemClickListener(new DrawerItemClickListener()); 

mDrawerLayout.setDrawerListener(actionBarDrawerToggle); 
    getActionBar().setDisplayHomeAsUpEnabled(true); 
// 
    // getActionBar().setHomeButtonEnabled(true); 

//  ActionBar actionBar = getActionBar(); 
//  actionBar.setDisplayShowHomeEnabled(false); 
//  actionBar.setDisplayShowCustomEnabled(true); 
//  actionBar.setDisplayShowTitleEnabled(false); 
//  View customView = getLayoutInflater().inflate(R.layout.activity_main, null); 
//  actionBar.setCustomView(customView); 
//  Toolbar parent =(Toolbar) customView.getParent(); 
//  parent.setContentInsetsAbsolute(0,0); 




    } 
    //other methods 
    } 

activity_main。 xml

<android.support.v4.widget.DrawerLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_gravity="center" 

    > 
    <!-- The main content view --> 

    <fragment xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/fragment_as_list" 
    android:name="ivano.android.com.xx" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
     /> 

    <ListView android:id="@+id/left_drawer" 
     android:layout_width="240dp" 

     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:choiceMode="singleChoice" 
     android:divider="@android:color/transparent" 
     android:dividerHeight="19dp" 
     android:background="@drawable/image_background" 
     android:paddingTop="?android:attr/actionBarSize" 

     android:paddingLeft="@dimen/activity_horizontal_margin" 

     android:paddingRight="@dimen/activity_horizontal_margin" 

     android:paddingBottom="@dimen/activity_vertical_margin" 
     /> 
</android.support.v4.widget.DrawerLayout> 
+0

您應該使用[支持導航欄](https://developer.android.com/training/implementing-navigation/nav-drawer.html)。這將有助於協調。 [This](http://codetheory.in/android-navigation-drawer/)博客文章告訴你如何使用默認的漢堡包圖標。您可以用任何顏色爲主題添加顏色。 – nukeforum

+0

@nukeforum感謝您的關注;對於支持導航欄,您給我的鏈接與我在帖子中指出的相同,即我想你的意思是使用V4庫,這正是我正在使用的。我不明白的是爲什麼圖標的行爲與預期不同 – trocchietto

回答