如何重写操作栏后退按钮在Android的? [英] how to override action bar back button in android?

查看:131
本文介绍了如何重写操作栏后退按钮在Android的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是我的查询 我想不硬键返回按钮,该活动自定义在行动栏按钮? 我有覆盖onBack pressed()方法,它与我的模拟器的后退按钮而不是

here is my query I want to customize the activity back button in action bar not in hard key back button? I have override the onBackPressed() method it works with my emulator back button and not

用行动吧后退按钮。

我希望它发生在动作条上?我怎样才能做到这一点? 这是我的code

I want it to happen with action bar? How can I do this? Here is my code

@Override
public void onBackPressed()
{

    Toast.makeText(getApplicationContext(),"Back button clicked", Toast.LENGTH_SHORT).show(); 
    return;
}

我已经使用这个面包回来pressed无论是工作或没有,但实际执行的变化要搬回previous活动。但是这是不工作的按钮present在最前的操作栏(除了活动名称)。

I have used this toast whether back pressed is working or not but the actual implementation changes like to move back to previous activity. but this is not working with the button present on Top of Action bar (Besides Title of the activity).

请任何一个可以指定我的问题。

Please any one could specify me the problem.

推荐答案

我觉得要覆盖的home键的点击操作。您可以覆盖在你的活动像这样的这种功能。

I think you want to override the click operation of home button. You can override this functionality like this in your activity.

        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
                switch (item.getItemId()) {
                case android.R.id.home:
                       Toast.makeText(getApplicationContext(),"Back button clicked", Toast.LENGTH_SHORT).show(); 
                    break;
                }
                return true;
        }

这篇关于如何重写操作栏后退按钮在Android的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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