2011-01-27 56 views
6

嗨我试图重写IME操作来显示虚拟键盘上的搜索。我的EditText处于放置在活动中的控件中。android-控制IME显示搜索操作而不是输入

以下是我有:

<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" /> 

在代码中我有这样的监听器上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,他们都不工作。这是怎么回事?

预先感谢您!

+0

基本上我已经从控制中删除了这个,并将其添加到一个活动,它仍然无法正常工作。我也尝试了sendMessage。没有!机器人:imeOptions = “actionSend | flagNoEnterAction” \t \t \t \t安卓的inputType = “textShortMessage | textAutoCorrect | textCapSentences | textMultiLine” 它就像IME某处完全禁用或重写的一些设置。我所做的只是在xml中添加了选项,然后尝试查看显示内容。我每次都得到相同的窗口。无论如何都不会更改虚拟键盘。 – dropsOfJupiter 2011-01-27 19:38:21

回答

2

已更新为droid 2.2并开始工作。可怕的错误!

3

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

相关问题