6

我正在使用 actionbarsherlock,我想在操作栏中使用编辑文本和按钮。我浏览了许多文件和帖子,但还没有找到解决方案。

如何在 Android 操作栏中添加编辑文本?

4

2 回答 2

7

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.

于 2012-07-24T20:24:06.463 回答
3

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?

于 2012-07-24T20:26:21.700 回答