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

android – 使用ActionBarSherlock左上角的图标进行导航,第1张

概述使用 here开发者指南,我试图让我的图标导航回我的主屏幕.我目前有一个按钮来执行此 *** 作,并在onOptionsItemSelected()方法中复制并粘贴代码.然而,点击图标永远不会做任何事情.这是ActionBar和ActionBarSherlock的不同之处吗? 这是作为示例给出的代码: @Overridepublic boolean onOptionsItemSelected(MenuI 使用 here开发者指南,我试图让我的图标导航回我的主屏幕.我目前有一个按钮来执行此 *** 作,并在onoptionsItemSelected()方法中复制并粘贴代码.然而,点击图标永远不会做任何事情.这是Actionbar和ActionbarSherlock的不同之处吗?

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

@OverrIDepublic 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,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 );}

当我点击图标时,没有任何反应.代码中的日志调用也没有显示在我的LogCat中.

解决方法 您可能无法启用ABS活动徽标.在onCreate()中添加
getSupportActionbar().setdisplayHomeAsUpEnabled(true);

此外,如果您还没有这样做,请阅读Implementing Ancestral Navigation,以便正确导航(忽略他们使用getActionbar(),他们没有使用ABS,这是实际的AndroID API Action bar方法).

总结

以上是内存溢出为你收集整理的android – 使用ActionBarSherlock左上角的图标进行导航全部内容,希望文章能够帮你解决android – 使用ActionBarSherlock左上角的图标进行导航所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/web/1135991.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存