Manzur Husain
Manzur Husain

Reputation: 149

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?

Upvotes: 6

Views: 15919

Answers (2)

Android2390
Android2390

Reputation: 1150

So you should check out the documentation for the action bar sherlock found at the website.

Basically to add something to the action bar sherlock you have to add it in terms of Menu items like as follows :

    @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

}

You can also check out the question that is asked at : ActionBarSherlock with multiple MenuItems?

Upvotes: 3

CommonsWare
CommonsWare

Reputation: 1006829

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.

Upvotes: 7

Related Questions