我使用底部导航活动模板创建一个android项目,然后得到三个默认片段,
在方法中:DashboardFragment的onCreateView,我添加了getActivity()。setTitle(“ Important”);
但是标题(在屏幕的左上角)仍然是“仪表板”,为什么没有更改为“重要”?我想用代码更改标题,我想在运行应用程序时更改标题,而不仅仅是在mobile_navigation.xml中进行配置]
谢谢。
这里是mobile_navigation.xml这是mobile_navigation.xml
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/mobile_navigation"
app:startDestination="@+id/navigation_home">
<fragment
android:id="@+id/navigation_home"
android:name="com.example.testfragmentjump.ui.home.HomeFragment"
android:label="@string/title_home"
tools:layout="@layout/fragment_home" />
<fragment
android:id="@+id/navigation_dashboard"
android:name="com.example.testfragmentjump.ui.dashboard.DashboardFragment"
android:label="@string/title_dashboard"
tools:layout="@layout/fragment_dashboard" />
<fragment
android:id="@+id/navigation_notifications"
android:name="com.example.testfragmentjump.ui.notifications.NotificationsFragment"
android:laabel="@string/title_notifications"
tools:layout="@layout/fragment_notifications" />
</navigation>