在 Android 中实现类似 iPhone 的后退按钮?

发布于 2024-10-07 22:55:20 字数 175 浏览 0 评论 0原文

我希望在其中一个活动的左上角有一个按钮,用于在堆栈上保存其下方活动的名称。这可能吗?该按钮本质上只是完成当前活动,我只需将文本设置为类似于堆栈上其下方活动的标签之类的内容。

我有一个半工作的解决方案,我只需将一个额外的字符串传递给活动,无论我从哪里开始它,这允许我将文本设置为任何有意义的内容。当我使用通知时这不起作用。

I'd like to have a button in the top left corner of one of my activities that holds the name of the activity under it on the stack. Is this possible? The button will essentially just finish the current activity, I just need to set the text to something like the label for the activity below it on the stack.

I've got a half-working solution where I just pass a string-extra to the activity wherever I start it from, which allows me to set the text to anything that makes sense. This does not work when I'm using notifications.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ゞ记忆︶ㄣ 2024-10-14 22:55:20

您还可以使用自定义 Application 对象 作为单例来存储名称最后一个已知活动的(在每个活动的 onCreate 中设置),但是如果您要启动多个任务或具有不同亲和力的任务,则这将无法正常工作。

但在这里质疑你的基本假设:你的应用程序所做的事情是否如此不寻常,以至于你需要占用一大块屏幕空间,并引入一个对于 Android 用户来说完全不熟悉的导航元素,他们希望只使用物理后退按钮并看到标题栏中当前应用程序/活动的名称(不是前一个)?

You could also use a custom Application object as a singleton to store the name of the last known activity (setting that in each activity's onCreate), but if you're launching multiple tasks or tasks with different affinities this won't really work properly.

But question your basic assumptions here: Is what your app is doing so unusual that you need to use up a chunk of screen real estate and introduce a navigational element totally unfamiliar to Android users who expect to just use the physical back button and to see the name of the current app/activity in the title bar (not the previous one)?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文