Cześć, mam MainActivity i 3 fragmenty. profileFragment, homeFragment i connectFragment który ma za zadanie wyswietlić profile i home fragment. Dolna nawigacja się wyświetla ale nie pokazuje się zaden layout.
MainActivity:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<fragment
android:id="@+id/fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="0dp"
android:layout_height="0dp"
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/nav_graph" />
</androidx.constraintlayout.widget.ConstraintLayout>
ConnectFragment:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ConnectFragment">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottomNavigationView"
android:layout_width="0dp"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimaryDark"
app:itemIconTint="@color/colorPrimary"
app:itemTextColor="@color/colorPrimary"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="@menu/nav_menu" />
<fragment
android:id="@+id/fragment2"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="0dp"
android:layout_height="0dp"
app:defaultNavHost="true"
app:layout_constraintBottom_toTopOf="@+id/bottomNavigationView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="parent"
app:navGraph="@navigation/bottom_nav" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
Dolne menu:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/homeFragment"
android:icon="@android:drawable/alert_light_frame"
android:title="home"
app:showAsAction="ifRoom" />
<item
android:id="@+id/profileFragment"
android:icon="@android:drawable/stat_sys_vp_phone_call"
android:title="profile"
app:showAsAction="ifRoom" />
</menu>
bottom_nav:
<?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"
app:startDestination="@id/homeFragment"
android:id="@+id/bottom_nav">
<fragment
android:id="@+id/homeFragment"
android:name="com.example.navigationarchitecture.HomeFragment"
android:label="home"
tools:layout="@layout/fragment_home" />
<fragment
android:id="@+id/profileFragment"
android:name="com.example.navigationarchitecture.ProfileFragment"
android:label="profile"
tools:layout="@layout/fragment_profile" />
</navigation>
i nav_graph:
<?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"
app:startDestination="@id/connect"
android:id="@+id/nav_graph">
<fragment
android:id="@+id/connect"
android:name="com.example.navigationarchitecture.ConnectFragment"
android:label="connect Fragment"
tools:layout="@layout/fragment_connect">
</fragment>
<fragment
android:id="@+id/home"
android:name="com.example.navigationarchitecture.HomeFragment"
android:label="home Fragment"
tools:layout="@layout/fragment_home">
</fragment>
<fragment
android:id="@+id/profile"
android:name="com.example.navigationarchitecture.ProfileFragment"
android:label="profile Fragment"
tools:layout="@layout/fragment_profile">
</fragment>
</navigation>
Dolna nawigacja wygląda mniej więcej tak jak na ss'ie. Problem jest taki że cały layout jest biały, nie wyświetla się ani profile ani home fragment. Tak jakby wyświetlał się pusty <fragment> </fragment> z pliku connect_fragment.xml ale jakoś layout z profile ani home fragment nie był tu dodawany żeby connect_fragment go wyświetlił.