How can I set back arrow in Android toolbar and also apply click listener?
If you want to know when home is clicked is an AppCompatActivity then you should try it like this: Use this code :
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
Listen for click events on android.R.id.home like usual:
@Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
if (menuItem.getItemId() == android.R.id.home) {
Intent intent = new Intent(CurrentActivity.this, MainActivity.class);
startActivity(intent);
finish();
}
return super.onOptionsItemSelected(menuItem);
}