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

岁酱吖の 提交于 2019-12-07 04:39:04

问题


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?


回答1:


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.




回答2:


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?



来源:https://stackoverflow.com/questions/11638226/how-i-can-add-edit-text-field-and-button-in-actionbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!