Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to block virtual keyboard while clicking on edittext in android?

Tags:

android

How to block virtual keyboard while clicking on edittext in android

like image 413
deepthi Avatar asked Dec 04 '09 06:12

deepthi


People also ask

How do I hide the soft keyboard on Android after clicking outside EditText?

Ok everyone knows that to hide a keyboard you need to implement: InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); imm. hideSoftInputFromWindow(getCurrentFocus(). getWindowToken(), 0);


3 Answers

Here is a website that will give you what you need.

As a summary, it provides links to InputMethodManager and View from Android Developers. It will reference to the getWindowToken inside of View and hideSoftInputFromWindow() for InputMethodManager

A better answer is given in the link, hope this helps.

EDIT

From the link posted above, here is an example to consume the onTouch event:

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
    }
 };

Here is another example from the same website. This claims to work but seems like a bad idea since your EditBox is NULL it will be no longer an editor:

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
}
});

Hope this points you in the right direction

like image 102
Anthony Forloney Avatar answered Oct 19 '22 13:10

Anthony Forloney


A simpler way, is to set focusable property of edit text false. In your EditText's XML set android:focusable="false"

like image 27
Symfony Dev Avatar answered Oct 19 '22 13:10

Symfony Dev


Another simpler way is adding android:focusableInTouchMode="false" line to your EditText's xml. Hope this helps.

like image 36
ACengiz Avatar answered Oct 19 '22 12:10

ACengiz