添加后退按钮操作栏按钮、操作

由网友(故事与你)分享简介:我一直在试图增加一个后退按钮的操作栏。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 th...

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

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);
    }
}
阅读全文

相关推荐

最新文章