Android ActionBarSherlock检测长按主菜单项

时间:2013-11-24 08:25:55

标签: android actionbarsherlock

在ABS中,我使用家作为后退按钮或向上导航。现在我要求如果用户长时间按下操作栏中的主页/向上按钮指示器,我需要显示主屏幕。对于正常按下,向上按钮将用作回流。我没有找到任何特定的方法来覆盖。目前我在onOptionsItemSelected中处理。

尝试在StackOverflow中搜索。没有找到任何可靠的例子。

更新 我尝试使用下面的代码,但在那种情况下,单击不能在设备上工作。虽然在模拟器中两次点击都正常工作。任何提示?

    View homeItem = findViewById(android.R.id.home);
    if(homeItem!=null){
        Log.d("homemenuitem","got it");
        View homeParent  = (View)homeItem.getParent();
        homeParent.setOnLongClickListener(new View.OnLongClickListener() {

            @Override
            public boolean onLongClick(View v) {
                // TODO Auto-generated method stub
                Log.d("homemenuitem","long click got it");
                return true;
            }
        });

    }

1 个答案:

答案 0 :(得分:0)

我感谢你的示例代码。 您可能不再需要解决方案,但我想为其他人编写。 : - )

您只需编辑一行:

View homeParent = (View)homeItem.getParent().getParent();

实际上,视图是LinearLayout,其中包含Home图标和标题TextView。 它适用于至少API LV14,但我不知道其他版本。  (ActionBar的视图层次结构可能因API LV而异)

相关问题