How to add text edit box and button in ActionBar?

I am using actionbarsherlock and I want to use Edit Text and Button on the action bar. I read a lot of documents and posts, but have not yet found a solution.

How to add edit text to Android action bar?

+6
source share
2 answers

Putting a regular Button in the action bar will look pretty awful, IMHO.

In doing so, you can use android:actionLayout on the <item> element in your menu XML resource. This should point to the name of the layout XML resource. This resource will be overstated in the action bar. You can get widgets by calling getActionView() on the MenuItem object corresponding to this <item> element.

Here is an example project demonstrating this. Here is the documentation for this technique.

+7
source

So, you should check the documentation for the toolbar found on the website.

Basically, to add something to the toolbar of the action bar, you have to add it to the menu items, for example:

  @Override public boolean onCreateOptionsMenu(Menu menu) { //inflate with your particular xml MenuInflater inflater = getSupportMenuInflater(); inflater.inflate(R.menu.child_add_menu, menu); return super.onCreateOptionsMenu(menu); } @Override public boolean onOptionsItemSelected(MenuItem item) { //your code here } 

Can you also check the question asked at ActionBarSherlock with multiple MenuItems?

+3
source

Source: https://habr.com/ru/post/921237/


All Articles