隐藏标题栏:
在onCreate()
内添加如下内容:
getSupportActionBar().hide();
隐藏状态栏:
在onCreate()
内添加如下内容:
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
给标题栏添加返回键:
在onCreate()
内添加如下内容:
ActionBar actionBar = getSupportActionBar();
if(actionBar != null){
actionBar.setHomeButtonEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
}
重写onOptionsItemSelected(MenuItem item)
这个方法,内容如下:
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()){
case android.R.id.home :
Intent intent = new Intent(NewsActivity.this,MainActivity.class);
startActivity(intent);
finish();
break;
default:
break;
}
return super.onOptionsItemSelected(item);
}
其中,第4行的Intent
重载方法内第一个参数为当前活动的context,第二个参数为要返回的活动类。另外需要注意的是,如果设置了隐藏标题栏,那么设置标题栏返回键就不会显示出来。