使用导航组件深层链接处理数组查询参数

时间:2020-02-23 10:10:40

标签: android android-architecture-navigation android-navigation-graph

我在项目中使用单个活动结构,并且我想使用导航组件处理深层(应用程序)链接。一切都很好,但是我无法处理数组查询参数。我想获取 complex_types 作为String数组。

现有网址:

my.example.com/?guests=1&complex_types=hotel&complex_types=motel

nav_graph.xml:

     <fragment
        android:id="@+id/complexFragment"
        android:name="com.the.example.packagename.ComplexFragment"
        android:label="ComplexFragment">
        <argument
            android:name="guests"
            android:defaultValue="1"
            app:argType="integer" />
        <argument
            android:name="complexFilters"
            app:argType="???" />
        <deepLink
            android:id="@+id/deepLink_complex_fragment"
            app:uri="my.example.com/?guests={guests}&amp;complex_types={complexFilters}" />
    </fragment>

我不知道在 complexFilters 参数中必须使用哪种类型的argType代替 ???

1 个答案:

答案 0 :(得分:1)

在android编辑器中,有一个用于数组的复选框,或者您 enter image description here

,并且在xml导航图中将是这样

   <argument
        android:name="images"
        android:defaultValue="@null"
        app:argType="string[]"
        app:nullable="true" />