Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How I can add Edit Text field and button in ActionBar?

I am using actionbarsherlock and I want to use an Edit Text and a Button in the action bar. I I have gone through many documents and posts but haven't found a solution yet.

How do I add an Edit Text in the Android action bar?

like image 823
Manzur Husain Avatar asked Jul 24 '12 19:07

Manzur Husain


People also ask

What is action toolbar?

Android ActionBar is a menu bar that runs across the top of the activity screen in android. Android ActionBar can contain menu items which become visible when the user clicks the “menu” button. In general an ActionBar consists of the following four components: App Icon: App branding logo or icon will be displayed here.


1 Answers

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

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

Here is a sample project demonstrating this. Here is the documentation on this technique.

like image 114
CommonsWare Avatar answered Sep 28 '22 09:09

CommonsWare