本文介绍了片段未显示在Android导航组件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此架构是新手,正在尝试在 Android导航组件中添加多个片段,但 Fragments 在列表中不可见.

Am new with this architecture and am trying to add multiple fragments in the Android Navigation component but the Fragments are not visible in the list.

如您所见,主机是唯一可用的主机.

As you can see, The host is the only one available.

我也查看了这个问题,但是没有.不能帮我.

I also had a look at this question, but it didn't help me out.

现在,这些是文档中正在使用的依赖项:

Now, these are the dependencies am using from the documentation :

def nav_version = "2.1.0-beta02"
    def nav_version_ktx = "2.1.0-beta02"

     // Java
    implementation "androidx.navigation:navigation-fragment:$nav_version"
    implementation "androidx.navigation:navigation-ui:$nav_version"

    // Kotlin
    implementation "androidx.navigation:navigation-fragment-ktx:$nav_version_ktx"
    implementation "androidx.navigation:navigation-ui-ktx:$nav_version_ktx"

和这个:

buildscript {
    ext.kotlin_version = '1.3.31'
    repositories {
        google()
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()

    }
}

然后我的片段如下:

class BlankFragment2 : Fragment() {

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_blank_fragment2, container, false)
    }


}

它是 xml :

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
             xmlns:tools="http://schemas.android.com/tools"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             tools:context=".BlankFragment2">

    <!-- TODO: Update blank fragment layout -->
    <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="@string/hello_blank_fragment"/>

</FrameLayout>

我的android studio版本为 3.4.2

The version of my android studio is 3.4.2

这可能是什么原因?

推荐答案

我正在使用2.1.0-alpha02版本,没有任何问题.尝试更改您的nav_version_ktx和nav_version

I am using the version 2.1.0-alpha02 and have no problems.Try to change your nav_version_ktx and nav_version

这也是我的 github 上的示例,以防万一您想检查一下.但是我认为这是版本问题

Also this a sample on my github, just in case you want to check something. But i think it's a problem of version

这篇关于片段未显示在Android导航组件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-04 02:17