为了账号安全,请及时绑定邮箱和手机立即绑定

EditText 完成后软键盘再次打开

EditText 完成后软键盘再次打开

千万里不及你 2023-02-23 17:39:57
所以我有custom alert dialog一个EditText。每当我点击一个按钮进行确认,或者如果我点击软键盘自己的完成按钮,我已经对应用程序进行了编程以关闭对话框。但是由于某些奇怪的原因,soft-keyboard在关闭警报对话框后仍然打开...最后的这段代码 buttonConfirm是我试图解决这个问题的。出于某种原因,代码不适用于按钮本身,但代码确实适用于软键盘中的完成按钮buttonConfirm.setOnClickListener(new     View.OnClickListener()    {..............    .................         closeKeyboard();         Handler handler = new Handler();         handler.postDelayed(new Runnable() {         @Override         public void run() {             dialog.dismiss();         }     }, 100); // 5000ms delay}//This is the code for the done-button in the `soft keyboard`textinputEdit.setOnEditorActionListener(new OnEditorActionListener() {        @Override        public boolean onEditorAction(TextView v, int actionId, KeyEvent event){         if(actionId==EditorInfo.IME_ACTION_DONE){              buttonConfirm.performClick();         }         return false;       }});那么,为什么在直接按下按钮时它会起作用而不是按钮本身呢?这对我来说很奇怪.. 任何人都知道这到底是怎么回事?:(
查看完整描述

2 回答

?
冉冉说

TA贡献1877条经验 获得超1个赞

单击完成按钮时,调用hideSoftInputFromWindow方法 -

InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);


查看完整回答
反对 回复 2023-02-23
?
函数式编程

TA贡献1807条经验 获得超9个赞

public void hideSoftKeyboard(Context context, View view) {

        try {

            InputMethodManager inputMethodManager =

                    (InputMethodManager) context.getSystemService(

                            Activity.INPUT_METHOD_SERVICE);

            inputMethodManager.hideSoftInputFromWindow(

                    view.getWindowToken(), 0);

        } catch (Exception e) {

            e.printStackTrace();

        }

    }

用法


textinputEdit.setOnEditorActionListener(new OnEditorActionListener() {

                    @Override

                    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {

                    if(actionId==EditorInfo.IME_ACTION_DONE){

                        buttonConfirm.performClick();

                        hideSoftKeyboard(YourActivityName.this,textinputEdit);

                    }

                    return false;

                }

            });


查看完整回答
反对 回复 2023-02-23
  • 2 回答
  • 0 关注
  • 109 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信