简体   繁体   中英

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.

I've tried:

  • Using an onclick event
  • Using a focuschanged event
  • Changing properties of the EditText (focusable etc...)

Note: I am currently using Paranoid Android. The EditText is Multiline.

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

android:textIsSelectable="true"

Please start by omitting any requestFocus defined for your EditText. 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:

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
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:singleLine="true"
        android:imeOptions="actionGo"/>

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