简体   繁体   English

更改其他活动的活动标签(操作栏标题)?

[英]Change activity label (Action bar title) from another activity?

我想知道是否有一种方法可以将一个活动标签从另一个活动更改?

您可以使用setTitle()方法更改操作栏的标题:

setTitle("awsome");

You are only able to access one Activity instance at a time (visible one) so you can not call setTitle on invisable Activity directly. 您一次只能访问一个Activity实例(可见的一个实例),因此不能直接在不可见的Activity上调用setTitle。

The solution is you need to have Global variable to store the Activity title ( can use Static variable or Application field). 解决方案是您需要具有Global变量来存储Activity标题(可以使用Static变量或Application字段)。 When button click - you update Global variable. 单击按钮时-更新全局变量。 When Activity onResume, you set title in Global variable to the Activity by calling setTitle. 当Activity为onResume时,您可以通过调用setTitle在Global变量中将标题设置为Activity。

Use an EventBus like: https://github.com/greenrobot/EventBus 使用EventBus,例如: https : //github.com/greenrobot/EventBus

Well use EventBus everywhere! 随处使用EventBus! EventBus is a very powerful concept! EventBus是一个非常强大的概念!

An alternative would be to startActivityForResult() and the other one will return the new ActionBarTitle as result, but EventBus is definitely better! 一种替代方法是startActivityForResult(),另一种将作为结果返回新的ActionBarTitle,但EventBus绝对更好!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM