【问题标题】:Is it possible to make the label attribute flexible in Navigation Component?Navigation Component 中的 label 属性是否可以变灵活?
【发布时间】:2023-02-21 13:22:36
【问题描述】:
<fragment
    android:id="@+id/navigationMain_fragment_profileFragment"
    android:name="com.test.fragments.ProfileFragment"
    android:label="luq281"
    tools:layout="@layout/fragment_profile">

    <argument
        android:name="userId"
        app:argType="integer" />

    <argument
        android:name="username"
        app:argType="string" />

</fragment>

是否可以使标签属性从特定参数(例如用户名参数)中读取值?

我知道如何以编程方式完成它,但我想用 XML 本身来完成。

可不可以?

【问题讨论】:

    标签: android android-jetpack android-architecture-navigation android-jetpack-navigation


    【解决方案1】:

    对的,这是可能的。

    使用用户名参数作为标签:

    <fragment
        android:id="@+id/navigationMain_fragment_profileFragment"
        android:name="com.test.fragments.ProfileFragment"
        android:label="{username}"
        tools:layout="@layout/fragment_profile">
    
        <argument
            android:name="userId"
            app:argType="integer" />
    
        <argument
            android:name="username"
            app:argType="string" />
    
    </fragment>
    

    【讨论】:

      猜你喜欢
      • 2022-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-29
      • 2023-02-15
      • 2021-07-19
      相关资源
      最近更新 更多