Skip to content

Instantly share code, notes, and snippets.

@foundkey
Last active November 27, 2018 10:17
Show Gist options
  • Save foundkey/f87347150ac2208fb9047d60d6dc7f6e to your computer and use it in GitHub Desktop.
Save foundkey/f87347150ac2208fb9047d60d6dc7f6e to your computer and use it in GitHub Desktop.
标题栏显示返回按钮
package com.toby.personal.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MenuItem;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
android.support.v7.app.ActionBar actionBar = getSupportActionBar();
if(actionBar != null){
actionBar.setHomeButtonEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
this.finish(); // back button
return true;
}
return super.onOptionsItemSelected(item);
}
}
//作者:赵者也
//链接:https://www.jianshu.com/p/3600b2178afa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment