添加后退按钮操作栏 [英] add back button to action bar

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

问题描述

我一直在试图增加一个后退按钮的操作栏。

I have been trying to add a back button to the action bar.

我想我的观点看起来是这样的:

I want my view to look like this:

我想补充的后退按钮的操作栏的左侧。

I want to add the back button in the left of the action bar.

我说这code

ActionBar actionBar = getActionBar();

actionBar.setDisplayHomeAsUpEnabled(true);

,但它不工作

but it doesn't work.

我该如何解决这个问题?

How can I fix this?

推荐答案

设置完成后 actionBar.setHomeButtonEnabled(真);

添加以下code:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            // app icon in action bar clicked; goto parent activity.
            this.finish();
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}

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

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