actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true); //给左上角图标的左边加上一个返回的图标
//getActionBar().setHomeButtonEnabled(true); //决定左上角的图标是否可以点击。没有向左的小图标。 true 图标可以点击 false 不可以点击。默认为true。
它的id是android.R.id.home。
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
// TODO Auto-generated method stub
if(item.getItemId() == android.R.id.home)
{
Intent parentIntent = new Intent(this, MainActivity.class);
parentIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
parentIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
parentIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
finish();
startActivity(parentIntent);
return true;
}
return super.onOptionsItemSelected(item);
}