如何检测的动作条标题的点击? [英] How can I detect a click on the ActionBar title?

查看:101
本文介绍了如何检测的动作条标题的点击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关特定客户的需求,我需要让我的应用程序(不会在市场被出版)用户点击动作条的标题来执行某些操作。

For specific customer requirement, I need to allow the user of my app ( won't be published in Market) to click on the ActionBar title to execute some actions.

我一直在寻找在Android源代码,但我无法找到的动作条的TextView称号的ID。

I have been looking in the Android source, but I am not able to find an ID for the actionBar TextView title.

有没有一种合适的方式来处理这样的点击?

Is there a proper way to handle such clicks?

推荐答案

标题是不点击AFAIK。图标/标识是点击 - 你会得到通过 android.R.id.home onOptionsItemSelected()。可以想象,标题也路线这样一来,虽然他们不提它,我不会依赖于它。

The title is non-clickable AFAIK. The icon/logo is clickable -- you'll get that via android.R.id.home in onOptionsItemSelected(). Conceivably, the title also routes this way, though they don't mention it and I wouldn't rely upon it.

这听起来像你想有一个微调供用户选择的行动来执行。如果是这样,使用 setListNavigationCallbacks()。如果要删除标题为现在是多余的,使用 setDisplayOptions(0,DISPLAY_SHOW_TITLE)

It sounds like you want a Spinner for the user to choose the actions to execute. If so, use setListNavigationCallbacks(). If you want to remove the title as now being superfluous, use setDisplayOptions(0, DISPLAY_SHOW_TITLE).

如果你想比其他东西一微调上的操作栏的左侧,使用 setDisplayOptions(DISPLAY_SHOW_CUSTOM,DISPLAY_SHOW_CUSTOM) setCustomView()。注意,这种方法是不推荐(避免在操作使用自定义导航模式巴),因为它可能无法与手机正常工作,特别是在肖像模式。

If you want something other than a Spinner on the left side of the action bar, use setDisplayOptions(DISPLAY_SHOW_CUSTOM, DISPLAY_SHOW_CUSTOM) and setCustomView(). Note that this approach is not recommended ("Avoid using custom navigation modes in the action bar"), as it may not work well with phones, particularly in portrait mode.

另一种可能性是,除去的标题和使用,而不是图标一个标志,并在标志有你标题作为图像的一部分。整个徽标应该点击,拿起通过 onOptionsItemSelected()

Another possibility would be to remove the title and use a logo instead of the icon, and in the logo have your "title" as part of the image. The whole logo should be clickable, picked up via onOptionsItemSelected().

这篇关于如何检测的动作条标题的点击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆