将活动添加到导航抽屉布局中,全部设计在空活动中

发布于 2025-01-13 06:23:29 字数 11138 浏览 0 评论 0原文

我创建了一个应用程序,其中我设计了一个带有导航抽屉布局的仪表板活动,所有活动都设计在一个空活动中。现在我想将现有活动与导航抽屉项目连接起来,而不使用片段。我现在可以做什么? NBI 在这里使用 kotlin。

dashboaed xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout 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"
    tools:context=".Dashboard"
    android:id="@+id/drawerlayout"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">


    <com.google.android.material.navigation.NavigationView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:id="@+id/navigationdrawer"
        app:headerLayout="@layout/headerfile"
        app:menu="@menu/sidemenu"
        android:layout_gravity="start"/>


    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">


    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">




    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/purple_200"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:title="TripEasy"
        app:titleMarginStart="40dp"
        tools:ignore="MissingConstraints" />


        <ImageView
            android:id="@+id/imageView"
            android:layout_width="160dp"
            android:layout_height="160dp"
            android:layout_marginEnd="16dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toEndOf="@+id/textView6"
            app:layout_constraintTop_toBottomOf="@+id/toolbar"
            app:srcCompat="@drawable/road_trip" />


    <LinearLayout
        android:id="@+id/linearLayout"
        android:layout_width="match_parent"
        android:layout_height="170dp"
        android:layout_marginTop="7dp"
        android:orientation="horizontal"
        android:padding="10dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/imageView">

        <androidx.cardview.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="10dp"
            android:layout_weight="1"
            app:cardElevation="5dp">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <ImageView
                    android:id="@+id/imageView3"
                    android:layout_width="wrap_content"
                    android:layout_height="90dp"
                    app:srcCompat="@drawable/architecture_and_city" />

                <TextView
                    android:id="@+id/cities"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@id/imageView3"
                    android:layout_centerHorizontal="true"
                    android:layout_marginTop="5dp"
                    android:fontFamily="sans-serif-smallcaps"
                    android:text="Cities"
                    android:textStyle="bold" />

            </RelativeLayout>
        </androidx.cardview.widget.CardView>

        <androidx.cardview.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="10dp"
            android:layout_weight="1"
            app:cardElevation="5dp">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <ImageView
                    android:id="@+id/imageView4"
                    android:layout_width="wrap_content"
                    android:layout_height="90dp"
                    app:srcCompat="@drawable/telephone" />

                <TextView
                    android:id="@+id/emergencyNum"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@id/imageView4"
                    android:layout_centerHorizontal="true"
                    android:layout_marginTop="5dp"
                    android:fontFamily="sans-serif-smallcaps"
                    android:text="Emergency Number"
                    android:textStyle="bold" />

            </RelativeLayout>
        </androidx.cardview.widget.CardView>

    </LinearLayout>



    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="170dp"
        android:orientation="horizontal"
        android:padding="10dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/linearLayout">

        <androidx.cardview.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="10dp"
            android:layout_weight="1"
            app:cardElevation="5dp">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <ImageView
                    android:id="@+id/imageView5"
                    android:layout_width="wrap_content"
                    android:layout_height="90dp"
                    app:srcCompat="@drawable/video" />

                <TextView
                    android:id="@+id/video"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@id/imageView5"
                    android:layout_centerHorizontal="true"
                    android:layout_marginTop="5dp"
                    android:fontFamily="sans-serif-smallcaps"
                    android:textStyle="bold"
                    android:text="Videos" />

            </RelativeLayout>
        </androidx.cardview.widget.CardView>

        <androidx.cardview.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="10dp"
            android:layout_weight="1"
            app:cardElevation="5dp">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <ImageView
                    android:id="@+id/imageView6"
                    android:layout_width="wrap_content"
                    android:layout_height="90dp"
                    app:srcCompat="@drawable/group" />

                <TextView
                    android:id="@+id/credits"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@id/imageView6"
                    android:layout_centerHorizontal="true"
                    android:layout_marginTop="5dp"
                    android:fontFamily="sans-serif-smallcaps"
                    android:text="Credits"
                    android:textStyle="bold" />

            </RelativeLayout>
        </androidx.cardview.widget.CardView>

      </LinearLayout>

        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="24dp"
            android:layout_marginEnd="16dp"
            android:fontFamily="@font/abril_fatface"
            android:text="TripEasy"
            android:textSize="30dp"
            app:layout_constraintEnd_toStartOf="@+id/imageView"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/toolbar" />

        <TextView
            android:id="@+id/textView6"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="16dp"
            android:text="Make your journey easy"
            app:layout_constraintEnd_toStartOf="@+id/imageView"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/textView3" />
    </androidx.constraintlayout.widget.ConstraintLayout>

    </ScrollView>

</androidx.drawerlayout.widget.DrawerLayout>

侧边菜单栏

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <group android:checkableBehavior="single">

        <item android:id="@+id/dashboard_menu"
            android:icon="@drawable/dashboard"
            android:title="Dashboard"/>

        <item android:id="@+id/cities"
            android:icon="@drawable/condo"
            android:title="Cities"/>
    </group>

    <group android:checkableBehavior="single">
        <item android:title="Authentication">


            <menu>

                <item android:id="@+id/registration"
                    android:icon="@drawable/personal"
                    android:title="Registration"/>

                <item android:id="@+id/logout"
                    android:icon="@drawable/logout"
                    android:title="Logout"/>



            </menu>
        </item>

    </group>

</menu>

头文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="180dp"
    android:background="@color/purple_200"
    android:orientation="vertical"
    android:gravity="center"
    android:padding="20dp">

    <ImageView
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:src="@drawable/road_trip"/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:fontFamily="@font/abril_fatface"
        android:text="TripEasy"
        android:textColor="@color/black"
        android:textSize="27sp"
        android:textStyle="bold" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Make your journey easier"
        android:textColor="@color/black"
        android:textSize="15dp"/>



</LinearLayout>

I have created an app where i have designed a dashboard activity with navigation drawer layout ,all designed in an empty activity.Now i want to connect my exiting acitivities with the navigation drawer item without using fragment.What can I do now? N.B.I am using kotlin here.

dashboaed xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout 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"
    tools:context=".Dashboard"
    android:id="@+id/drawerlayout"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">


    <com.google.android.material.navigation.NavigationView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:id="@+id/navigationdrawer"
        app:headerLayout="@layout/headerfile"
        app:menu="@menu/sidemenu"
        android:layout_gravity="start"/>


    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">


    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">




    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/purple_200"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:title="TripEasy"
        app:titleMarginStart="40dp"
        tools:ignore="MissingConstraints" />


        <ImageView
            android:id="@+id/imageView"
            android:layout_width="160dp"
            android:layout_height="160dp"
            android:layout_marginEnd="16dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toEndOf="@+id/textView6"
            app:layout_constraintTop_toBottomOf="@+id/toolbar"
            app:srcCompat="@drawable/road_trip" />


    <LinearLayout
        android:id="@+id/linearLayout"
        android:layout_width="match_parent"
        android:layout_height="170dp"
        android:layout_marginTop="7dp"
        android:orientation="horizontal"
        android:padding="10dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/imageView">

        <androidx.cardview.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="10dp"
            android:layout_weight="1"
            app:cardElevation="5dp">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <ImageView
                    android:id="@+id/imageView3"
                    android:layout_width="wrap_content"
                    android:layout_height="90dp"
                    app:srcCompat="@drawable/architecture_and_city" />

                <TextView
                    android:id="@+id/cities"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@id/imageView3"
                    android:layout_centerHorizontal="true"
                    android:layout_marginTop="5dp"
                    android:fontFamily="sans-serif-smallcaps"
                    android:text="Cities"
                    android:textStyle="bold" />

            </RelativeLayout>
        </androidx.cardview.widget.CardView>

        <androidx.cardview.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="10dp"
            android:layout_weight="1"
            app:cardElevation="5dp">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <ImageView
                    android:id="@+id/imageView4"
                    android:layout_width="wrap_content"
                    android:layout_height="90dp"
                    app:srcCompat="@drawable/telephone" />

                <TextView
                    android:id="@+id/emergencyNum"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@id/imageView4"
                    android:layout_centerHorizontal="true"
                    android:layout_marginTop="5dp"
                    android:fontFamily="sans-serif-smallcaps"
                    android:text="Emergency Number"
                    android:textStyle="bold" />

            </RelativeLayout>
        </androidx.cardview.widget.CardView>

    </LinearLayout>



    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="170dp"
        android:orientation="horizontal"
        android:padding="10dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/linearLayout">

        <androidx.cardview.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="10dp"
            android:layout_weight="1"
            app:cardElevation="5dp">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <ImageView
                    android:id="@+id/imageView5"
                    android:layout_width="wrap_content"
                    android:layout_height="90dp"
                    app:srcCompat="@drawable/video" />

                <TextView
                    android:id="@+id/video"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@id/imageView5"
                    android:layout_centerHorizontal="true"
                    android:layout_marginTop="5dp"
                    android:fontFamily="sans-serif-smallcaps"
                    android:textStyle="bold"
                    android:text="Videos" />

            </RelativeLayout>
        </androidx.cardview.widget.CardView>

        <androidx.cardview.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="10dp"
            android:layout_weight="1"
            app:cardElevation="5dp">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <ImageView
                    android:id="@+id/imageView6"
                    android:layout_width="wrap_content"
                    android:layout_height="90dp"
                    app:srcCompat="@drawable/group" />

                <TextView
                    android:id="@+id/credits"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@id/imageView6"
                    android:layout_centerHorizontal="true"
                    android:layout_marginTop="5dp"
                    android:fontFamily="sans-serif-smallcaps"
                    android:text="Credits"
                    android:textStyle="bold" />

            </RelativeLayout>
        </androidx.cardview.widget.CardView>

      </LinearLayout>

        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="24dp"
            android:layout_marginEnd="16dp"
            android:fontFamily="@font/abril_fatface"
            android:text="TripEasy"
            android:textSize="30dp"
            app:layout_constraintEnd_toStartOf="@+id/imageView"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/toolbar" />

        <TextView
            android:id="@+id/textView6"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="16dp"
            android:text="Make your journey easy"
            app:layout_constraintEnd_toStartOf="@+id/imageView"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/textView3" />
    </androidx.constraintlayout.widget.ConstraintLayout>

    </ScrollView>

</androidx.drawerlayout.widget.DrawerLayout>

side menu bar

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <group android:checkableBehavior="single">

        <item android:id="@+id/dashboard_menu"
            android:icon="@drawable/dashboard"
            android:title="Dashboard"/>

        <item android:id="@+id/cities"
            android:icon="@drawable/condo"
            android:title="Cities"/>
    </group>

    <group android:checkableBehavior="single">
        <item android:title="Authentication">


            <menu>

                <item android:id="@+id/registration"
                    android:icon="@drawable/personal"
                    android:title="Registration"/>

                <item android:id="@+id/logout"
                    android:icon="@drawable/logout"
                    android:title="Logout"/>



            </menu>
        </item>

    </group>

</menu>

header file

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="180dp"
    android:background="@color/purple_200"
    android:orientation="vertical"
    android:gravity="center"
    android:padding="20dp">

    <ImageView
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:src="@drawable/road_trip"/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:fontFamily="@font/abril_fatface"
        android:text="TripEasy"
        android:textColor="@color/black"
        android:textSize="27sp"
        android:textStyle="bold" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Make your journey easier"
        android:textColor="@color/black"
        android:textSize="15dp"/>



</LinearLayout>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文