Android 使用ActionBarSherlock左上角的图标导航

Android 使用ActionBarSherlock左上角的图标导航,android,android-actionbar,actionbarsherlock,Android,Android Actionbar,Actionbarsherlock,使用找到的开发者指南,我试图让我的图标导航回我的主屏幕。我目前有一个按钮可以执行此操作,并在onOptionsItemSelected()方法中复制和粘贴代码。但是,点击图标不会有任何效果。这是ActionBar和ActionBarSherlock的区别吗 这是作为示例给出的代码: @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android

使用找到的开发者指南,我试图让我的图标导航回我的主屏幕。我目前有一个按钮可以执行此操作,并在
onOptionsItemSelected()
方法中复制和粘贴代码。但是,点击图标不会有任何效果。这是ActionBar和ActionBarSherlock的区别吗

这是作为示例给出的代码:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
    case android.R.id.home:
        // app icon in action bar clicked; go home
        Intent intent = new Intent(this, HomeActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);
        return true;
    default:
        return super.onOptionsItemSelected(item);
}
}
这是我正在使用的代码:

public boolean onOptionsItemSelected( MenuItem item ) {
    switch( item.getItemId() ) {
    case R.id.mainTopBluetoothState:
        Toast.makeText( this, "BluetoothState", Toast.LENGTH_SHORT ).show();
        return true;
    case R.id.mainTopAppState:
        Toast.makeText( this,  "BluetoothState",  Toast.LENGTH_SHORT ).show();
        return true;
    case android.R.id.home:
        Log.i( "In Home", "In Home" );
        killToasts();
        dispatchKeyEvent(new KeyEvent( KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK ));
        finish();
        return true;
    }
    return super.onOptionsItemSelected( item );
}

当我点击图标时,什么也没发生。代码中的
Log
调用也不会显示在my
LogCat
中。

您可能没有启用ABS活动徽标可单击。将此添加到
onCreate()

另外,如果您还没有这样做,请阅读以便正确地向上导航(忽略他们使用的
getActionBar()
,他们没有使用ABS,这是实际的Android API操作栏方法)

getSupportActionBar().setDisplayHomeAsUpEnabled(true);