如何在执行某些动作时显示碎片



实际上我正在开发一个具有导航抽屉的应用程序,我想使用片段而不是单独的活动。我想如何完成?预先感谢。

检查此示例代码。希望这对您有帮助。

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <include layout="@layout/toolbar_layout">
        <!--The Toolbar Layout if you have toolbar-->
    </include>
    <FrameLayout
        android:id="@+id/base_container"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">
        <!--The layout where you need to add different
            fragments on click of nabigation items-->
    </FrameLayout>
</LinearLayout>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:orientation="vertical">
 <!--The navigation drawer items-->
</LinearLayout>

最新更新