I'm using Android Studio 3.4.2 and trying to implement some basic navigation features in my app.
I am following the official documentation to setup a NavHostFragement (via a FragmentContainerView) and linking the appropriate graph to it. However, when I do this, I get an error on the app:navGraph attribute stating:
Unexpected resource type: 'navigation' expected: string.
This causes the app to crash on start-up and the nav_graph itself gives a warning that it's not linked to a host.
Main activity:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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=".MainActivity">
<androidx.fragment.app.FragmentContainerView
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="8dp"
app:defaultNavHost="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolbar"
app:navGraph="@navigation/nav_graph" />
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="358dp"
android:layout_height="64dp"
android:layout_marginStart="8dp"
android:layout_marginBottom="696dp"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0" />
</androidx.constraintlayout.widget.ConstraintLayout>
nav_graph.xml (It already contains a couple off fragments and actions):
<?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/nav_graph"
app:startDestination="@id/home_screen">
<fragment
android:id="@+id/home_screen"
android:name="com.example.ordersysteem2.home_screen"
android:label="home_screen" >
<action
android:id="@+id/action_home_screen_to_prepare"
app:destination="@id/prepare" />
<action
android:id="@+id/action_home_screen_to_kalkoenSalami"
app:destination="@id/kalkoenSalami" />
</fragment>
<fragment
android:id="@+id/prepare"
android:name="com.example.ordersysteem2.prepare"
android:label="fragment_prepare"
tools:layout="@layout/fragment_prepare" />
<fragment
android:id="@+id/kalkoenSalami"
android:name="com.example.ordersysteem2.kalkoenSalami"
android:label="fragment_kalkoen_salami"
tools:layout="@layout/fragment_kalkoen_salami" />
</navigation>