从空白活动切换到导航抽屉活动

时间:2016-08-02 12:01:13

标签: android android-studio android-activity

我使用空白活动启动了一个项目。是否可以切换到导航抽屉活动而无需创建新项目?

2 个答案:

答案 0 :(得分:0)

您可以在CoOrdinator视图中包含您的内容,然后在drawerlayout中包含协调器布局,并像这样添加NavigationView:

<android.support.v4.widget.DrawerLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:foregroundGravity="top"
android:fitsSystemWindows="true"
tools:openDrawer="start">

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <include layout="YOUR_LAYOUT_HERE"/>

</LinearLayout>

</android.support.design.widget.CoordinatorLayout>

<android.support.design.widget.NavigationView
    android:layout_height="match_parent"
    android:layout_width="wrap_content"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/navigation_drawer_header"
    app:menu="@menu/navigation_drawer_content"/>

</android.support.v4.widget.DrawerLayout>

答案 1 :(得分:0)

删除现有活动及其布局,然后右键单击现有活动包,然后选择新建,然后选择活动并选择您的活动。

相关问题