[英]How can i hide/disable done button on soft keyboard android?
I am working with Amazon S3 api. 我正在使用Amazon S3 API。
Problem: Working with TextWatcher. 问题:使用TextWatcher。 As soon as user enters more than 3 characters in the edittext, api is called and it shows matched results. 一旦用户在edittext中输入了3个以上的字符,就会调用api并显示匹配的结果。 The problem starts as soon the user hit the done/enter button on soft keyboard, the api is called again and it searches again. 用户单击软键盘上的完成/输入按钮后,问题立即开始,再次调用api并再次搜索。 Can i stop this second call somehow? 我可以以某种方式停止第二个电话吗? Thanks! 谢谢!
you can change it from xml: 您可以从xml更改它:
<EditText
...
android:imeOptions="actionNone"/>
or from code: 或通过代码:
editText.setImeOptions(EditorInfo.IME_ACTION_NONE);
It will remove the done button whenever user trigger the softkeybord 每当用户触发softkeybord时,它将删除完成按钮
也许您可以尝试在控件中覆盖onKeyListener方法,以使其检测所按下的键是否为“ enter”,并添加您希望您的“ enter”键执行的代码?
edittext.setOnKeyListener(new View.OnKeyListener() {
just handle done click and hide the soft keyboard 只需处理完成的单击并隐藏软键盘
editText = (EditText) findViewById(R.id.edit_text);
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
// hide your keyboard here
try {
InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
if (inputMethodManager != null && activity.getCurrentFocus() != null) {
inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
}
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
return false;
}
});
Add 加
android:maxLines="1"
to you xml and enter button should be disabled. 到您的xml并输入按钮应被禁用。
You can Do like editText.setImeOptions(EditorInfo.IME_ACTION_NONE);
您可以像editText.setImeOptions(EditorInfo.IME_ACTION_NONE);
but it won't hide the Enter/Next 但它不会隐藏Enter / Next
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.