问题
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