>In oncreate(); write this line->
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
>then implement below method in that class
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// app icon in action bar clicked; go home
onBackPressed();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
Firstly Use this:
> ActionBar bar = getSupportActionBar();
> bar.setDisplayHomeAsUpEnabled(true);
Then set operation of button click in onOptionsItemSelected method
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}