Ich habe ein Projekt mit leerer Aktivität gestartet. Ist es möglich, zur Navigationsschubladenaktivität zu wechseln, ohne ein neues Projekt erstellen zu müssen?Von leerer Aktivität zu Navigationsschubladen-Aktivität wechseln
1
A
Antwort
0
Sie können Ihre Inhalte innerhalb eines Koordinators Ansicht einpacken dann in einem drawerlayout den Koordinator Layout und die NavigationView hinzufügen wie folgt:
<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>
0
die vorhandene Aktivität und das Layout löschen und rechts klicken, um Ihre vorhandene Aktivität Paket Wählen Sie dann Neu und dann Aktivität und wählen Sie Ihre Aktivität aus.
ja warum nicht hier http://stackoverflow.com/questions/19980945/how-do-i-add-navigation-drawer-to-my-existing-code –
Datei> neu> Aktivität> Schublade Aktivität –