How to make navigation drawer without actionbar

谁说我不能喝 提交于 2019-12-25 04:37:16

问题


I am trying to implement navigation drawer without ActionBar.

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???


回答1:


To hide actionbar, simply do this:

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



回答2:


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>


来源:https://stackoverflow.com/questions/30963293/how-to-make-navigation-drawer-without-actionbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!