how to override action bar back button in android?

I think you want to override the click operation of home button. You can override this functionality like this in your activity.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        Toast.makeText(getApplicationContext(),"Back button clicked", Toast.LENGTH_SHORT).show(); 
        break;
    }
    return true;
}

If you want ActionBar back button behave same way as hardware back button:

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
            if (item.getItemId() == android.R.id.home) {
                    onBackPressed();
                    return true;
            }
            return false;
    }

Tags:

Java

Android