如何在android中点击edittext时阻止虚拟键盘?

dee*_*thi 17 android

如何virtual keyboard在android中单击edittext时阻止

Ant*_*ney 46

是一个可以满足您需求的网站.

作为总结,它提供了InputMethodManagerViewAndroid开发者之间的链接.它将引用getWindowToken内部ViewhideSoftInputFromWindow()forInputMethodManager

链接中给出了更好的答案,希望这会有所帮助.

编辑

从上面发布的链接,这是一个使用onTouch事件的示例:

editText_input_field.setOnTouchListener(otl);

private OnTouchListener otl = new OnTouchListener() {
    public boolean onTouch (View v, MotionEvent event) {
            return true; // the listener has consumed the event
    }
 };
Run Code Online (Sandbox Code Playgroud)

这是同一网站的另一个例子.这要求工作,但似乎是一个糟糕的主意,因为你EditBoxNULL这将是不再编辑:

MyEditor.setOnTouchListener(new OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent event) {
    int inType = MyEditor.getInputType(); // backup the input type
    MyEditor.setInputType(InputType.TYPE_NULL); // disable soft input
    MyEditor.onTouchEvent(event); // call native handler
    MyEditor.setInputType(inType); // restore input type
    return true; // consume touch event
}
});
Run Code Online (Sandbox Code Playgroud)

希望这能指出你正确的方向


小智 7

一种更简单的方法是将编辑文本的可聚焦属性设置为false.在EditText的XML集中android:focusable ="false"