将FragmentContainerView与导航组件一起使用?

将FragmentContainerView与导航组件一起使用?

问题描述:

更新为导航后 2.2.0-beta01 从以前的版本开始,lint会发出警告,要求将<fragment>标记替换为FragmentContainerView.

After updating to Navigation 2.2.0-beta01 from the previous version, lint gives a warning about replacing the <fragment> tag with FragmentContainerView.

但是,仅更换标签似乎可以防止导航图膨胀.

However, replacing the tag alone seems to prevent the navigation graph from being inflated.

根据 2.2.0-alpha01 FragmentContainerView在内部使用.我们应该忽略棉绒警告吗?

According to 2.2.0-alpha01, FragmentContainerView is used internally. Should we ignore the lint warning?

activity_main.xml

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- Lint warning: "Replace the <fragment> tag with FragmentContainerView. -->
    <fragment
        android:id="@+id/nav_host_main"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:defaultNavHost="true"
        app:navGraph="@navigation/nav_graph_main"/>

    <!-- other elements -->

</androidx.constraintlayout.widget.ConstraintLayout>

重要!不同版本的FragmentContainerView存在已知问题.使用前,请参阅更改日志.通读错误修复程序并使用该库的最新版本.

Important! There are known issues with different versions of FragmentContainerView. See the changelog before using. Read through bug fixes and use a recent version of the library.

现在,您还应该声明对片段1.2.0-beta02的依赖性,因为它包含此用例的修复程序.

For now, you should also declare dependency on Fragment 1.2.0-beta02 as it includes a fix for this use case.

implementation "androidx.fragment:fragment:1.2.0-beta02"

版本1.2.0-beta02

2019年10月11日

Version 1.2.0-beta02

October 11, 2019

错误修复

解决了Fragment的onInflate()无法从FragmentContainerView接收适当属性的问题,打破了诸如NavHostFragment的情况. ( b/142421837 )

Fixed an issue where Fragment's onInflate() did not receive proper attributes from FragmentContainerView, breaking cases such as NavHostFragment. (b/142421837)

来源: https://developer.android.com/jetpack/androidx/releases/fragment#1.2.0-beta02