简体   繁体   English

Android单击EditText不会显示软键盘

[英]Android click on EditText won't show softkeyboard

It happens when the user dismisses the softkeyboard and then tries to click/gain focus on the EditText again, nothing happens only the cursor is shown - I want to show the keyboard again. 当用户关闭软键盘然后尝试再次单击/获得对EditText的焦点时,会发生这种情况,仅显示光标不会发生任何事情-我想再次显示键盘。

I've tried: 我试过了:

  • Using an onclick event 使用onclick事件
  • Using a focuschanged event 使用焦点变更事件
  • Changing properties of the EditText (focusable etc...) 更改EditText的属性(可聚焦等)

Note: I am currently using Paranoid Android. 注意:我目前正在使用偏执Android。 The EditText is Multiline. EditText是多行。

我找到了解决方案,只需要从EditText中删除以下属性:

android:textIsSelectable="true"

Please start by omitting any requestFocus defined for your EditText. 请首先省略为您的EditText定义的任何requestFocus。 there's a known bug that prevents keyboard from showning if the latter is set. 有一个已知的错误 ,如果设置了键盘,则会阻止键盘显示。


If that doesn't work for you, create a focus listener and in it programmatically open the virt keyboard: 如果那对您不起作用,请创建一个焦点侦听器,并以编程方式打开virt键盘:

editTxt.setOnFocusChangeListener(new OnFocusChangeListener() {          
    public void onFocusChange(View v, boolean hasFocus) {
        if(hasFocus) {
            // show keyboard
            InputMethodManager imm = (InputMethodManager)this.getSystemService(Service.INPUT_METHOD_SERVICE);
            imm.showSoftInput(editTxt, 0);

        }
    }
});

Here is a solution: 这是一个解决方案:

final InputMethodManager imm=(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
EditText e= (EditText) findViewById(R.id.editText1);
e.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            imm.showSoftInput(e, InputMethodManager.SHOW_IMPLICIT);
        }
    });
    e.setOnEditorActionListener(new OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            // TODO Auto-generated method stub
            if(actionId==EditorInfo.IME_ACTION_GO){
                imm.hideSoftInputFromWindow(e.getWindowToken(), 0);
                //Do you work here
            }
            return false;
        }
    });

and the edittext will be: 并且edittext将是:

<EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:singleLine="true"
        android:imeOptions="actionGo"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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