Android的福尔摩斯动作条上按钮 [英] Android Sherlock ActionBar Up button

查看:168
本文介绍了Android的福尔摩斯动作条上按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

近流有一个小箭头采用U给previous活动点击时

我要做出同样的在我的应用程序,我用

  getSupportActionBar()setDisplayHomeAsUpEnabled(真)。
 

我是否需要使用 onOptionsItemSelected

该箭头出现,但没有发生一次点击。

和我有我的菜单中有两个项目,他们似乎无处不在,我称之为 OnCreateOptionsMenu

这是我想要的只出现在我的最后一项活动,我的项目code如何?

 <项目
机器人:ID =@ + ID / bAbout
机器人:标题=关于
机器人:showAsAction =总是/>
 

解决方案

是的,你必须执行 onOptionsItemSelected()。该ID为该按钮为 android.R.id.home

 公共布尔onOptionsItemSelected(菜单项项){
    开关(item.getItemId()){

    案例android.R.id.home:
         //做你想做的,例如完()
         打破;

    默认:
        返回super.onOptionsItemSelected(项目);
    }
}
 

  

和我有我的菜单中有两个项目,他们似乎无处不在,我叫OnCreateOptionsMenu

我不知道这里的​​问题是。当然,你应该只执行 onCreateOptionsMenu()和膨胀,你想让它的菜单资源。删除 onCreateOptionsMenu()对于这些不应该有这些选项应该工作的所有活动。

Near Stream there is a small arrow that takes u to the previous activity when clicked

I want to make the same in my app, I used

  getSupportActionBar().setDisplayHomeAsUpEnabled(true);

do I need to use onOptionsItemSelected ?

The arrow is appearing, but nothing happens once clicked.

And I have two Items in my menu, they appear everywhere where I call OnCreateOptionsMenu

this is my item code where I want to to appear only in my last activity, How ?

      <item 
android:id="@+id/bAbout"
android:title="About"
android:showAsAction="always"/>

解决方案

Yes you have to implement onOptionsItemSelected(). The id for that button is android.R.id.home

public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {

    case android.R.id.home:
         // Do whatever you want, e.g. finish()
         break;

    default:
        return super.onOptionsItemSelected(item);
    }
}

And I have two Items in my menu, they appear everywhere where I call OnCreateOptionsMenu

I'm not sure what the problem here is. Of course you should only implement onCreateOptionsMenu() and inflate that menu resource where you want it. Removing onCreateOptionsMenu() for all activities which are not supposed to have these options should work.

这篇关于Android的福尔摩斯动作条上按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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