如何重写操作栏后退按钮在Android的?重写、按钮、操作、Android

2023-09-05 01:41:40 作者:欺骗弥漫空气、

这里是我的查询 我想不硬键返回按钮,该活动自定义在行动栏按钮? 我有覆盖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;
        }