How to make navigation drawer without actionbar

2019-09-10 13:30发布

I am trying to implement navigation drawer without ActionBar.

enter image description here

There is a small layout and inside it there is a button. When the button is clicked then the navigation drawer will open. The navigation drawer will be under the button. How can i implement this in android???

2条回答
▲ chillily
2楼-- · 2019-09-10 13:59

Define your xml like this and you are done

<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>
查看更多
三岁会撩人
3楼-- · 2019-09-10 14:13

To hide actionbar, simply do this:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getSupportActionBar().hide(); 
}
查看更多
登录 后发表回答