android - 控制IME显示搜索操作而不是输入

时间:2011-01-27 17:33:57

标签: android

您好我正在尝试覆盖IME操作以在虚拟键盘上显示搜索。我的EditText位于活动的控件中。

这就是我所拥有的:

<EditText android:id="@+id/txtSearch"
    android:textSize="18dp"
    android:textColor="@color/main_text_black"
    android:layout_width="247dp" 
    android:layout_height="fill_parent"
    android:imeOptions="actionSearch"
    android:gravity="center_vertical"
    android:singleLine="true"
    android:background="@null"
    android:layout_alignParentLeft="true"
    android:layout_marginLeft="38px" />

在Code中,我在EditText上设置了这个监听器:

@Override
public boolean onEditorAction(TextView view, int arg1, KeyEvent arg2) {
    if((arg1 == EditorInfo.IME_ACTION_SEARCH) {
        for(OnSearchListener listener : _listeners) {
            listener.OnSearch(view, getSearchString());
        }
    }
    InputMethodManager imm = 
        (InputMethodManager)_context.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);

    return false;
}
当我按下“未识别”的回车键时,

arg1始终以0返回。我也尝试了不同的键盘,如sendMessage,但它们都没有。发生了什么事?

提前谢谢!

2 个答案:

答案 0 :(得分:3)

您需要在xml文件中指定android:inputType =“text”属性。

答案 1 :(得分:2)

更新到droid 2.2并开始工作。可怕的虫子!

相关问题