【问题标题】:About NavigationFragment关于导航片段
【发布时间】:2021-01-18 14:04:14
【问题描述】:

NavgationHostFragment 不工作。

//activity_main
<?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">


    <fragment
        android:id="@+id/fragment3"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:defaultNavHost="true"
        app:navGraph="@navigation/nav_main"
        tools:layout_editor_absoluteX="131dp"
        tools:layout_editor_absoluteY="201dp" />

</androidx.constraintlayout.widget.ConstraintLayout>


//nav_main
<?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_main"
    app:startDestination="@id/welcomeFragment2">
    <fragment
        android:id="@+id/welcomeFragment2"
        android:name="com.example.fragmenttest.WelcomeFragment"
        android:label="WelcomeFragment" />
</navigation>

我不知道为什么。

Fragment 或其他文档中没有描述该过程。

请给我一个提示,如何让 Fragment xml 显示而不是 Activity_main。 我已经为此苦苦挣扎了好几天。 感谢您的帮助。

【问题讨论】:

  • 从代码的角度来看,一切似乎都很好。添加有关您几天来一直在努力解决的错误的更多详细信息

标签: android kotlin fragment


【解决方案1】:

对不起,我没有添加适配器,它没有显示出来。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-09-19
    • 2023-02-14
    • 1970-01-01
    • 2019-03-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多