簡體   English   中英

如何在沒有操作欄的情況下制作導航抽屜

[英]How to make navigation drawer without actionbar

我正在嘗試在沒有ActionBar情況下實現導航抽屜。

在此處輸入圖片說明

布局很小,里面有一個按鈕。 單擊該按鈕后,導航抽屜將打開。 導航抽屜將位於按鈕下方。 我如何在Android中實現呢???

這樣定義您的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">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="100dp" // static height for view or keep it dimen.xml
        android:background="#21ef70"
        android:gravity="bottom"
        android:orientation="horizontal">

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Click"
            android:id="@+id/button2" />
    </LinearLayout>
</LinearLayout>

<!-- Listview to display navigation menu -->
<ListView
    android:id="@+id/list_slidermenu"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:layout_marginTop="100dp" // same margin as of layout
    android:choiceMode="singleChoice"
    android:dividerHeight="1dp" />
</android.support.v4.widget.DrawerLayout>

要隱藏動作欄,只需執行以下操作:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getSupportActionBar().hide(); 
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM