Android: Disable soft keyboard at all EditTexts

2020-01-25 01:17发布

I am working on a dialog at Android with a few EditTexts. I've put this line at the onCreate() in order to disable the soft keyboard:

Keypad.this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

The problem is that it works only when the dialog appear and doing nothing. When I move to the next EditText, the keyboard appears and not going down.

Does anybody have an idea how to solve this issue?

13条回答
【Aperson】
2楼-- · 2020-01-25 01:41

Put this in Oncreate Method

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
查看更多
贪生不怕死
3楼-- · 2020-01-25 01:42

create your own class that extends EditText and override the onCheckIsTextEditor():

public class NoImeEditText extends EditText {
    public NoImeEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    @Override
    public boolean onCheckIsTextEditor() {
        return false;
    }
}
查看更多
够拽才男人
4楼-- · 2020-01-25 01:43

in order to disable ANDROID SOFT INPUT KEYBOARD xml file doesn't help in my case calling the setInputType method on EditText object in java file works great. here is the code.

EditTextInputObj = (EditText) findViewById(R.id.EditTextInput);
EditTextInputObj.setInputType(InputType.TYPE_NULL); 
查看更多
劫难
5楼-- · 2020-01-25 01:45

If you take look on onCheckIsTextEditor() method implementation (in TextView), it looks like this:

@Override
public boolean onCheckIsTextEditor() {
    return mInputType != EditorInfo.TYPE_NULL;
}

This means you don't have to subclass, you can just:

((EditText) findViewById(R.id.editText1)).setInputType(InputType.TYPE_NULL); 

I tried setting android:inputType="none" in layout xml but it didn't work for me, so I did it programmatically.

查看更多
唯我独甜
6楼-- · 2020-01-25 01:47

Know its too late, but have you tried the following setting to EditText in your layout ?

android:inputType="none"

UPDATE

Use,

editText.setInputType(InputType.TYPE_NULL)
editText.setFocusable(false)
查看更多
贪生不怕死
7楼-- · 2020-01-25 01:53

Try this out..

edittext.setInputType(InputType.TYPE_NULL);      
if (android.os.Build.VERSION.SDK_INT >= 11)   
{  
    edittext.setRawInputType(InputType.TYPE_CLASS_TEXT);  
    edittext.setTextIsSelectable(true);  
}
查看更多
登录 后发表回答