gpt4 book ai didi

android - 使用 ActionBarSherlock 左上角的图标进行导航

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:57:48 25 4
gpt4 key购买 nike

使用开发人员指南发现 here ,我正在尝试让我的图标导航回我的主屏幕。我目前有一个执行此操作的按钮,并且已将代码复制并粘贴到 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 调用也从未显示在我的 LogCat 中。

最佳答案

您可能没有使 ABS Activity Logo 可点击。在 onCreate()

中添加
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

此外,如果您还没有这样做,请阅读 Implementing Ancestral Navigation所以你正确地向上导航(忽略他们对 getActionBar() 的使用,他们没有使用 ABS,这是实际的 Android API Action Bar 方法)。

关于android - 使用 ActionBarSherlock 左上角的图标进行导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14488229/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com