“Back button” using getSupportActionbar and appcompat v7 toolbar

Add this method in onCreate():

getSupportActionBar().setDisplayHomeAsUpEnabled(true);

Then override the onOptionItemSelected() as below:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            onBackPressed();
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)