0

我一直在關注谷歌的官方指南來創建一個簡單的導航抽屜。到目前爲止,我已經改變了我的Main_Activity.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"> 
    <!-- The main content view --> 
    <FrameLayout 
     android:id="@+id/content_frame" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 
    <!-- The navigation drawer --> 
    <ListView android:id="@+id/drawer_list" 
     android:layout_width="240dp" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:choiceMode="singleChoice" 
     android:divider="@android:color/transparent" 
     android:dividerHeight="0dp" 
     android:background="#111"/> 
</android.support.v4.widget.DrawerLayout> 

然後在我的MainActivity.java我添加了這些:

mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); 
    mDrawerList = (ListView) findViewById(R.id.drawer_list); 

    // Creating an ArrayAdapter to add items to the listview mDrawerList 
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(getBaseContext(), 
      R.layout.drawer_list_item, mOptions); 

    // Setting the adapter on mDrawerList 
    mDrawerList.setAdapter(adapter); 

我也創建了以下

的XML drawer_list_item
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/text1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:textAppearance="?android:attr/textAppearanceListItemSmall" 
    android:gravity="center_vertical" 
    android:paddingLeft="16dp" 
    android:paddingRight="16dp" 
    android:textColor="#fff" 
    android:background="?android:attr/activatedBackgroundIndicator" 
    android:minHeight="?android:attr/listPreferredItemHeightSmall"/> 

但我仍然沒有什麼,甚至沒有錯誤。它只是不起作用,我想我錯過了一些簡單的,謝謝!

+1

請更新的問題,並插入XML佈局 –

+0

是否有mOptions什麼? – ElDuderino

+0

private String [] mOptions = {「Login」,「Search」}; –

回答

1

按照this link,希望它會幫助你很多。

休息,如果你堅持在任何地方自由地問我..

+0

它確實。我錯過了 getActionBar()。setDisplayHomeAsUpEnabled(true); getActionBar()。setHomeButtonEnabled(true); 謝謝! –

+0

@George D-你的歡迎。 :) – Namy

+0

請投票了答案 – Namy