1

Original problem of menu item's not opening activity was solved by removing all the XML code incide ConstraintLayout. I added NavigationDrawer after creating all the stuff inside ConstraintLayout. How can i make both NavigationDrawer and my own stuff work together?

<?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:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/main_screen_image"
    android:fitsSystemWindows="true"
    tools:context=".HomeScreen"
    tools:openDrawer="start">

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

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/purple_200"
            android:elevation="4dp"
            android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
        <!--Dark text
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"-->

        <!--        Container for fragments-->
        <!--<FrameLayout
            android:id="@+id/fragment_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />-->

    </LinearLayout>

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

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:padding="20dp">

        <ImageView
            android:id="@+id/homeScreenLogo"
            android:layout_width="160dp"
            android:layout_height="160dp"
            android:layout_gravity="center"
            android:src="@drawable/kaznau_logo"
            app:layout_constraintBottom_toTopOf="@+id/guideline6"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.498"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <LinearLayout
            android:id="@+id/linearLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="50dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.4"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="@+id/guideline6">

            <com.google.android.material.button.MaterialButton
                android:id="@+id/btnAboutUniversity"
                android:layout_width="160dp"
                android:layout_height="50dp"
                android:drawableLeft="@drawable/ic_university"
                android:text="@string/s_about_kaznau"
                app:cornerRadius="5dp" />

            <View
                android:layout_width="0dp"
                android:layout_height="20dp"
                android:layout_weight="1" />

            <com.google.android.material.button.MaterialButton
                android:id="@+id/btnFaculties"
                android:layout_width="160dp"
                android:layout_height="50dp"
                android:drawableLeft="@drawable/ic_faculty"
                android:text="@string/s_faculty"
                app:cornerRadius="5dp" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/linearLayout2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/linearLayout">

            <com.google.android.material.button.MaterialButton
                android:id="@+id/btnNews"
                android:layout_width="160dp"
                android:layout_height="50dp"
                android:drawableLeft="@drawable/ic_baseline_article_24"
                android:text="@string/s_news"
                app:cornerRadius="5dp" />

            <View
                android:layout_width="0dp"
                android:layout_height="20dp"
                android:layout_weight="1" />

            <com.google.android.material.button.MaterialButton
                android:id="@+id/btnEvents"
                android:layout_width="160dp"
                android:layout_height="50dp"
                android:drawableLeft="@drawable/ic_baseline_event_24"
                android:text="@string/events_name"
                app:cornerRadius="5dp" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/linearLayout3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/linearLayout2">

            <com.google.android.material.button.MaterialButton
                android:id="@+id/btnLocations"
                android:layout_width="160dp"
                android:layout_height="50dp"
                android:drawableLeft="@drawable/ic_location"
                android:text="@string/s_locations"
                app:cornerRadius="5dp" />

            <View
                android:layout_width="0dp"
                android:layout_height="20dp"
                android:layout_weight="1" />

            <com.google.android.material.button.MaterialButton
                android:id="@+id/btnCampus"
                android:layout_width="160dp"
                android:layout_height="50dp"
                android:drawableLeft="@drawable/ic_campus"
                android:text="@string/s_campus"
                app:cornerRadius="5dp" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/linearLayout4"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/linearLayout3">

            <com.google.android.material.button.MaterialButton
                android:id="@+id/btnLinks"
                android:layout_width="160dp"
                android:layout_height="50dp"
                android:drawableLeft="@drawable/ic_links"
                android:text="@string/s_links"
                app:cornerRadius="5dp" />

            <View
                android:layout_width="0dp"
                android:layout_height="20dp"
                android:layout_weight="1" />

            <com.google.android.material.button.MaterialButton
                android:id="@+id/btnContacts"
                android:layout_width="160dp"
                android:layout_height="50dp"
                android:drawableLeft="@drawable/ic_contacts"
                android:text="@string/s_contacs"
                app:cornerRadius="5dp" />
        </LinearLayout>

        <com.google.android.material.button.MaterialButton
            android:id="@+id/btnAgrodamu"
            android:layout_width="wrap_content"
            android:layout_height="50dp"
            android:layout_gravity="center"
            android:text="@string/s_agrodamu"
            app:cornerRadius="5dp"
            app:layout_constraintBottom_toTopOf="@+id/guideline7"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.555"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/linearLayout4"
            app:layout_constraintVertical_bias="0.164" />

        <androidx.constraintlayout.widget.Guideline
            android:id="@+id/guideline6"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            app:layout_constraintGuide_begin="20dp"
            app:layout_constraintGuide_percent="0.4" />

        <androidx.constraintlayout.widget.Guideline
            android:id="@+id/guideline7"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            app:layout_constraintGuide_begin="20dp"
            app:layout_constraintGuide_percent="0.9" />
    </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.drawerlayout.widget.DrawerLayout>

I would be appreciated if you can also tell me how to make my XML code more clean, without losing the functionality and look of it. Thanks

2
  • Do you have any errors in the logcat?
    – Shay Kin
    Commented Apr 29, 2021 at 3:16
  • No, none. I also tried adding Toast to see a message when i click on item, but nothing happened. I thing, that item's on my navigation drawer are unclickable and i don't know why
    – Akzhan
    Commented Apr 29, 2021 at 4:07

1 Answer 1

0

Okay, I figured it out. You have to put the NavigationView at the bottom before closing the DrawerLayout tag

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.