【问题标题】:Switch from blank activity to navigation drawer activity从空白活动切换到导航抽屉活动
【发布时间】:2016-08-02 12:01:13
【问题描述】:

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

【问题讨论】:

标签: android android-studio android-activity


【解决方案1】:

您可以将内容包装在 CoOrdinator 视图中,然后将协调器布局放在抽屉布局中,然后像这样添加 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>

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多