I am able to create an actionbar with a custom back button as such:
// Calling the action bar
ActionBar actionBar = getSupportActionBar();
// Customize the back button
actionBar.setHomeAsUpIndicator(R.drawable.ic_baseline_arrow_back_24);
// Showing the back button in action bar
actionBar.setDisplayHomeAsUpEnabled(true);
What I am not certain now is that I wish to add a TextView in the same actionbar (towards the end of the actionbar) but I am not clear on how I can do so?
also I would need to add a onClickListened on the TextView as I would like for it to perform an action when user click on it.
Can anyone please let me know how I can achieve that?
2
Answers
actionbar.setTitle will change the title.
Using a Toolbar will be better if you want to customize it. can you give a more detailed example on what you are trying to achieve.
If I’m not wrong you are trying to add a TextView in your ActionBar which is not possible. The alternate approach is to use a Toolbar.
Inside your Toolbar add a ViewGroup (e.g. LinearLayout, RelativeLayout, etc) and define your TextView inside that ViewGroup.
Code Example