1

如何更改活动的标题?截至目前,它只显示程序的标题,我希望它显示我选择的内容,并且在我的应用程序中的每个页面/活动都不同,即我的主页可以在标题中显示青蛙(1/17),而另一个应用程序切换到的活动可以通过使用点击事件或使用对接在该标题中包含青蛙(2/17)

4

5 回答 5

1

If I understand you correctly, you would like something dynamic that changes the title (page count) when the button is pressed?

I would suggest the following:

private static int pageCount = 1; // global variable in class. Default page = 1

onCreate() {
setPage(pageCount); // Set the title for the first time

}

// When your button is clicked
private static onButton() {
pageCount++; // Increment page count by one
setPage(pageCount); // set the new title


}

private static setPage(int page) {
setTitle("frog(" + page + "/17)");

}

I hope this helps.

于 2013-08-28T17:34:35.483 回答
0

你可以在 android sdk sample ApiDemos 中找到结果,在 App -> Activity -> Custom Title 部分

于 2013-08-28T16:51:52.407 回答
0

您可以像这样在代码中设置标题:

setTitle("Some Title");

您也可以像这样在 xml 中执行此操作:

android:label="Some Title"
android:label="@strings/someTitle"
于 2013-08-27T07:22:09.913 回答
0

您可以通过以下代码以编程方式更改 Activity 的标题:

getActionBar.setTitle("Your_Activity_Name");
于 2013-08-28T17:27:20.473 回答
0

我只是在 RES 目录中查找“值”文件夹。在那里,您会看到一个名为 strings.xml 的文件。在该文件中,您可以找到所有活动标题的值。查找您要更改的活动并立即进行!示例:我要更改的活动是“新闻”,而我需要的标题是“这里”。我找到了这个值:中央

所以我把它改成这样:这里

它没有给我带来任何麻烦。

于 2019-03-24T01:36:09.727 回答