If the toolbar is used as an ActionBar, the view identifier will be android.R.id.home , and you would use onOptionsItemSelected(...) to know when it is clicked.
If it is not used as an ActionBar, the view identifier is -1, which does not have a specific identifier resource.
This means that you must use setNavigationOnClickListener() , but in either of two approaches:
or:
toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ... } });
or
private View.OnClickListener homeClickListener = new View.OnClickListener() { @Override public void onClick(View view) { ... } }; @Override protected void onCreate(...) { ... toolbar.setNavigationOnClickListener(homeClickListener); ... }
Pirdad sakhizada
source share