【问题标题】:How to Change the Title of Action-Bar?如何更改操作栏的标题?
【发布时间】:2020-11-13 09:59:09
【问题描述】:

我正在创建一个应用程序并使用导航组件,因此如果主片段被膨胀,则操作栏标题是主片段,当它导航到 firstDestination 片段操作栏标题必须是 firstDestination。 我怎么能这样做?

【问题讨论】:

  • 这是您要找的吗? Objects.requireNonNull(getSupportActionBar()).setTitle("whatever");
  • 只需使用图表中的标签

标签: android navigation components


【解决方案1】:

只需在导航图中使用android:label:

<navigation xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    app:startDestination="@id/firstFragment">
    <fragment
        android:id="@+id/firstFragment"
        android:label="First Fragment Title"
        .../>

    <fragment
        android:id="@+id/secondFragment"
        android:label="Second Fragment Title"
        .../>
</navigation>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-20
    • 1970-01-01
    相关资源
    最近更新 更多