I used Toolbar component in AppCompat library instead of Default Actionbar.
Compile time: I get compile-error that cannot find symbol android.R.id.home
public void setupActionBar() {
// Set a Toolbar to replace the ActionBar.
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if(id == R.id.action_help) {
showHelp();
return true;
}else if(id == android.R.id.home){
Log.d(TAG, "Back Button clicked!");
this.finish();
return true;
}
return super.onOptionsItemSelected(item);
}
android.R.id.home was introduced in API level 11. here is more detail: https://stackoverflow.com/a/18719090/2178694
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With