0

I asked this question before here but made a mistake with one of the codeblocks I posted. Here it is again for your reference

I have a standard bottom navigation selector using a navhost controller. I would like to add a PrefencesFragment that will be full screen. My issue is if I use the navcontroller it will use the navhost fragment which has the bottom navigation below it which will look weird.

I know I have to use a global destination as per documentation --> https://developer.android.com/guide/navigation/navigation-global-action

But how do I get it to replace the whole layout and not just navhost fragment?

I almost wish that I could just launch an activity and put the fragment in there. Would that be very bad style?

Here is my layout

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

    <androidx.constraintlayout.widget.ConstraintLayout
        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">

        <com.google.android.material.appbar.AppBarLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">

            <com.google.android.material.appbar.MaterialToolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="?attr/colorPrimary"
                android:minHeight="?attr/actionBarSize"
                android:theme="?attr/actionBarTheme"
                app:logo="@drawable/baseline_post_add_24"
                app:logoDescription="Postering With Passion"
                app:title="Postering With Passion"
                app:titleCentered="true"
                app:titleTextColor="@color/white"
                tools:layout_editor_absoluteX="0dp"
                tools:layout_editor_absoluteY="0dp" >

            <ProgressBar
                android:id="@+id/toolbar_progress_bar"
                android:layout_width="36dp"
                android:layout_height="36dp"
                android:indeterminateTint="#cccccc"
                android:indeterminateTintMode="src_in"
                android:indeterminate="true"
                android:layout_marginRight="4dp"
                android:layout_gravity="right"
                android:visibility="visible"
                />

            </com.google.android.material.appbar.MaterialToolbar>

        </com.google.android.material.appbar.AppBarLayout>

    <androidx.coordinatorlayout.widget.CoordinatorLayout
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        app:layout_constraintBottom_toTopOf="@+id/bottom_navigation_view"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_height="0dp"
        tools:context="com.plcoding.posterpalfeature.ui.activity.MainActivity">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/constraintLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <fragment
                android:id="@+id/navHostFragment"
                android:name="androidx.navigation.fragment.NavHostFragment"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:defaultNavHost="true"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:navGraph="@navigation/job_nav_graph" />

        </androidx.constraintlayout.widget.ConstraintLayout>

        <include
            android:id="@+id/bottom_sheet"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/background_bottom_sheet"
            app:layout_anchorGravity="bottom"
            app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"
            layout="@layout/layout_bottom_sheet"></include>


    </androidx.coordinatorlayout.widget.CoordinatorLayout>

        <com.google.android.material.bottomnavigation.BottomNavigationView
            android:id="@+id/bottom_navigation_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:menu="@menu/bottom_navigation_menu"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:labelVisibilityMode="labeled"
            app:contentInsetEnd="0dp"
            app:contentInsetStart="0dp"/>

        </androidx.constraintlayout.widget.ConstraintLayout>
</layout>

And here is the navigation file

<?xml version="1.0" encoding="utf-8"?>
<navigation 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/job_nav_graph"
    app:startDestination="@id/jobsListFragment">

        <fragment
            android:id="@+id/jobsListFragment"
            android:name="com.plcoding.posterpalfeature.ui.fragments.JobsListFragment"
            android:label="JobsListFragment"
            tools:layout="@layout/fragment_job_list">
            <action
                android:id="@+id/action_jobsListFragment_to_mapFragment"
                app:destination="@id/mapFragment"
                app:enterAnim="@anim/slide_in_left"
                app:exitAnim="@anim/slide_out_right"
                app:popEnterAnim="@anim/slide_in_left" />
            <action
                android:id="@+id/action_jobsListFragment_to_jobDetailFragment"
                app:destination="@id/jobDetailFragment"
                app:popUpTo="@id/jobsListFragment"
                app:popUpToInclusive="true" />
        </fragment>
        <fragment
            android:id="@+id/jobDetailFragment"
            android:name="com.plcoding.posterpalfeature.ui.fragments.JobDetailFragment"
            android:label="JobDetailFragment"
            tools:layout="@layout/fragment_job_detail">
            <argument
                android:name="jobId"
                android:defaultValue="1"
                app:argType="integer" />
        </fragment>
        <fragment
            android:id="@+id/mapFragment"
            android:name="com.plcoding.posterpalfeature.ui.fragments.MapFragment"
            android:label="MapFragment"
            tools:layout="@layout/fragment_map_detail" />
</navigation>

Sorry for the inconvenience.

user1743524
  • 655
  • 1
  • 7
  • 14

0 Answers0