I am using a custom toolbar. I need to add back button to it. Now I am using this code to add the back button.
Toolbar toolbar = (Toolbar) getActivity().find
use Method in Class your Activity
private void setupToolbar(){
Toolbar toolbar=(Toolbar)findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar=getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
}