我的应用有一个用于搜索的 AutoCompleteTextView。当它处于焦点状态时,我想禁用或更改返回键的功能以进行特定的函数调用。我尝试在我的布局 xml 中将以下属性添加到 AutoCompleteTextView
android:imeOptions="actionDone"
但它可以在我的模拟器上运行(当您单击回车时,键盘会消失)但它不能在我的设备上运行(运行 2.3.3 的 moto droidx)。
谁能告诉我如何使用 android:imeOptions="actionGo"将返回键链接到特定功能(在我的例子中是搜索功能)?
最佳答案
在 EditText
系列的 setOnEditorActionListener
事件中编写代码。喜欢
autoEditText.setOnEditorActionListener(new OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId,
KeyEvent event) {
if (event != null&& (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
InputMethodManager in = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
// in.hideSoftInputFromWindow(autoEditText.getApplicationWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
//Commented line is for hide keyboard. Just make above code as comment and test your requirement
//It will work for your need. I just putted that line for your understanding only
//You can use own requirement here also.
}
return false;
}
});
快乐编码:)
关于Android:当AutoCompleteTextView获得焦点时禁用(或改变)返回键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7266143/