简体   繁体   中英

How can i hide/disable done button on soft keyboard android?

I am working with Amazon S3 api.

Problem: Working with TextWatcher. As soon as user enters more than 3 characters in the edittext, api is called and it shows matched results. The problem starts as soon the user hit the done/enter button on soft keyboard, the api is called again and it searches again. Can i stop this second call somehow? Thanks!

you can change it from 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

也许您可以尝试在控件中覆盖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.

You can Do like editText.setImeOptions(EditorInfo.IME_ACTION_NONE);

but it won't hide the Enter/Next

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM