EditText中imeOptions属性使用及设置无效解决

虽然通常输入法软键盘右下角会是回车按键

但我们经常会看到点击不同的编辑框,输入法软键盘右下角会有不同的图标

点击浏览器网址栏的时候,输入法软键盘右下角会变成“GO”或“前往”

而我们点击Google搜索框,输入法软键盘右下角会变成 放大镜 或者“搜索”

而决定这个图标的变换的参数就是EditText中的 android:imeOptions

android:imeOptions的值有actionGo、 actionSend 、actionSearch、actionDone等,这些意思都很明显

<EditText
                android:id="@+id/setting_search_edit"
                android:layout_width="200dp"
                android:layout_height="20dp"
                android:layout_centerVertical="true"
                android:layout_marginLeft="30dp"
                android:background="@null"
                android:singleLine="true"
                android:imeOptions="actionSearch"
                android:textSize="11sp" />

在代码中通过editText.setOnEditorActionListener方法添加相应的监听,因为有些action是需要在代码中添加具体的相关操作的

mSearchEdit.setOnEditorActionListener(new OnEditorActionListener() {

@Override
            public boolean onEditorAction(TextView text, int actionId, KeyEvent event) {
                mSearch = true;
                if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                    nameList.clear();
                    idList.clear();
                    headpicList.clear();
                    for (int i = 0; i < blackListName.size(); i++) {
                        if (blackListName.get(i).contains(mSearchEdit.getText())) {
                            nameList.add(blackListName.get(i));
                            idList.add(blackListId.get(i));
                            headpicList.add(blackListHeadpic.get(i));
                        }
                    }
                    mAdapter = new BlackListAdapter(FilterlistActivity.this, mChecked, idList,
                            nameList, headpicList, photoLoader);
                    mListView.setAdapter(mAdapter);
                }
                return false;
            }
        });

设置无效时需要设置一下一项

1 将singleLine设置为true

2 将inputType设置为text

上一篇:AutomationAnywhere(AA)实现网页抓取


下一篇:ECharts JavaScript图表库 ECharts