Нижняя навигация не показывает фрагменты на android графике навигации реактивного пакета - PullRequest
0 голосов
/ 08 января 2020

У меня есть это приложение с двумя действиями, одно из которых является хостом для входа, регистрации и ... фрагментов, и если пользователь регистрируется, оно переходит к другому действию, которое содержит нижнюю навигацию и 5 фрагментов для переключения. Проблема заключается в том, что первое действие работает нормально, но когда я обедаю второе, отображается нижняя навигация и работает, но содержимое фрагментов не отображается! вот мой навигационный график:

<?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/main_nav_graph"
    app:startDestination="@id/homeFragment">

    <fragment
        android:id="@+id/homeFragment"
        android:name="com.prototype.nyx.HomeFragment"
        android:label="fragment_home"
        tools:layout="@layout/fragment_home" >
        <action
            android:id="@+id/action_homeFragment_to_walletFragment"
            app:destination="@id/walletFragment" />
    </fragment>
    <fragment
        android:id="@+id/walletFragment"
        android:name="com.prototype.nyx.WalletFragment"
        android:label="fragment_wallet"
        tools:layout="@layout/fragment_wallet" >
        <action
            android:id="@+id/action_walletFragment_to_addProductFragment"
            app:destination="@id/addProductFragment" />
    </fragment>
    <fragment
        android:id="@+id/addProductFragment"
        android:name="com.prototype.nyx.AddProductFragment"
        android:label="fragment_add_product"
        tools:layout="@layout/fragment_add_product" >
        <action
            android:id="@+id/action_addProductFragment_to_settingsFragment"
            app:destination="@id/settingsFragment" />
    </fragment>
    <fragment
        android:id="@+id/settingsFragment"
        android:name="com.prototype.nyx.SettingsFragment"
        android:label="fragment_settings"
        tools:layout="@layout/fragment_settings" >
        <action
            android:id="@+id/action_settingsFragment_to_profileFragment"
            app:destination="@id/profileFragment" />
    </fragment>
    <fragment
        android:id="@+id/profileFragment"
        android:name="com.prototype.nyx.ProfileFragment"
        android:label="fragment_profile"
        tools:layout="@layout/fragment_profile" />
</navigation>

и вот мое основное занятие и его макет:

package com.prototype.nyx;

import androidx.appcompat.app.AppCompatActivity;
import androidx.navigation.fragment.NavHostFragment;
import androidx.navigation.ui.NavigationUI;

import android.os.Bundle;

import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.ittianyu.bottomnavigationviewex.BottomNavigationViewEx;

public class MainActivity extends AppCompatActivity {

    private BottomNavigationView bottomNavigationView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        setUpNavigation();
    }

    public void setUpNavigation() {
        bottomNavigationView = findViewById(R.id.bottom_nav);
        NavHostFragment navHostFragment = (NavHostFragment) getSupportFragmentManager()
                .findFragmentById(R.id.main_nav_host_fragment);
        System.out.println("number of fragments is:"+navHostFragment.getChildFragmentManager()
                .getFragments().size());
        NavigationUI.setupWithNavController(bottomNavigationView,
                navHostFragment.getNavController());
    }
}

<?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"
    android:background="@color/white"
    tools:context=".MainActivity">

    <fragment
        android:id="@+id/main_nav_host_fragment"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:navGraph="@navigation/main_nav_graph" />



    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottom_nav"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:menu="@menu/bottom_nav_menu" />

</androidx.constraintlayout.widget.ConstraintLayout>

и меню:

    <?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="@drawable/ic_home"
        app:showAsAction="always"
        android:title="">
    </item>


    <item
        android:id="@id/walletFragment"
        android:icon="@drawable/ic_wallet"
        app:showAsAction="always"
        android:title="">
    </item>

    <item
        android:id="@id/addProductFragment"
        android:icon="@drawable/ic_add"
        app:showAsAction="always"
        android:title="">
    </item>

    <item
        android:id="@+id/settingsFragment"
        android:icon="@drawable/ic_settings"
        app:showAsAction="always"
        android:title="">
    </item>

    <item
        android:id="@id/profileFragment"
        android:icon="@drawable/ic_person_black_24dp"
        app:showAsAction="always"
        android:title="">
    </item>
</menu>

Сначала я Я подумал, что это основной макет деятельности, поэтому я попробовал макет кадра и координатор тоже. но ничего не получалось. один из моих фрагментов:

<?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=".HomeFragment">

    <TextView
        android:id="@+id/textView3"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="@string/hello_blank_fragment" />

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="256dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.498"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.063"
        tools:src="@tools:sample/avatars" />

</androidx.constraintlayout.widget.ConstraintLayout>

в чем проблема?

1 Ответ

2 голосов
/ 08 января 2020

попробуйте проверить имя пакета фрагмента и имя фрагмента attr в navgraph

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...