ActionbarSherlock:标题上的事件处理程序

发布于 2025-01-08 12:47:23 字数 217 浏览 5 评论 0原文

我正在使用 ActionbarSherlock

我在 java 代码中设置了 sherlock 操作栏的标题:

actionBar.setTitle(title);

我想知道,如何将事件处理程序添加到操作栏的标题?

I am using ActionbarSherlock .

I set the title for the sherlock action bar in my java code by:

actionBar.setTitle(title);

I am wondering, how can I add event handler to the title of action bar?

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

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

发布评论

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

评论(2

喜爱皱眉﹌ 2025-01-15 12:47:23

无法添加具有内置标题的事件。

但是,您可以使用 setCustomView 方法添加自己的 TextView,您可以在该方法上添加点击侦听器。

There is no way to add an event with the built-in title.

However, you can add your own TextView using the setCustomView method on which you can add a listener for click.

简单气质女生网名 2025-01-15 12:47:23

您还可以将标题设置为向上指示器,并像处理其他菜单项一样处理单击事件。

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

然后在处理所选选项时:

public boolean onOptionsItemSelected(final MenuItem item)
{
    switch (item.getItemId())
    {
        case android.R.id.home:
            // your title was clicked!
            return true;
    }
}

我应该注意,您的标题应该表现得像具有“向上”行为。我的意思是,将您的活动视为您最喜欢的操作系统上的目录结构。后退按钮将转到您刚才所在的位置,并且无论您如何到达那里,该标题都应该“向上”一个目录。

You can also set the title as an up indicator and handle that clicked as you would another menu item.

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

Then in handling the options selected:

public boolean onOptionsItemSelected(final MenuItem item)
{
    switch (item.getItemId())
    {
        case android.R.id.home:
            // your title was clicked!
            return true;
    }
}

I should caution, your title should act like it has "up" behavior. By that I mean that consider your activities like a directory structure on your favorite OS. The back button goes to the place you just were, and this title should go "up" one directory regardless of how you got there.

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