建设ActionMode在ActionBarSherlock自定义布局 [英] Building ActionMode with custom layout in ActionBarSherlock

查看:203
本文介绍了建设ActionMode在ActionBarSherlock自定义布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用ActionBarSherlock建立一些简单的应用刚刚起步, 在我的第一个画面我有简单的列表,我增加了新的菜单项中添加新项的列表:

I just starting using ActionBarSherlock for building some simple app, in my first screen I have simple list and I added new menu item for adding new item to the list:

MenuItem newItem = menu.add("New");
newItem.setIcon(R.drawable.ic_compose_inverse)
    .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

现在,当用户选择添加一个新的项目我想开始一个新的动作模式,增加新的项目,这一行动模式应包含文本框和按钮布局简单,所以我创造了这个布局:

now when user choose to add a new item I want to start a new action mode for adding new item, this action mode should contain a simple layout with text box and a button, so I created this layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

        <EditText
            android:id="@+id/text"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:inputType="text" >
        </EditText>
        <Button
            android:id="@+id/addBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/add" />
</LinearLayout>

所以现在我只需要这个布局设置了酒吧的新操作方式:

so now I just need to set this layout to the bar in the new action mode:

newItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                actionMode = startActionMode(new MyAction(ListEditor.this));
                return true;
            }
        });

和我的行动:

private final class MyAction implements ActionMode.Callback {
    ...
    @Override
    public boolean onCreateActionMode(ActionMode mode, Menu menu) {
        View customNav = LayoutInflater.from(context).inflate(R.layout.add_item, null);
        getSupportActionBar().setCustomView(customNav);
        getSupportActionBar().setDisplayShowCustomEnabled(true);
        return true;
    }
}

因此,基本上,我需要ActionModes和CustomNavigation从夏洛特例子之间的事情,但问题是,它设置布局主栏,而不是为新的酒吧,开在采取行动。

有什么建议?

推荐答案

您可能希望使用名为setCustomView的ActionMode类中的方法。

You probably want to use the method in the ActionMode class called "setCustomView" .

所以是这样的:

newItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            actionMode = startActionMode(new MyAction(ListEditor.this));
            actionMode.setCustomView(customNav);
            return true;
        }
    });

这篇关于建设ActionMode在ActionBarSherlock自定义布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆