简体   繁体   中英

Suppress appearance of the soft keyboard on EditText focus

I am trying to define a set of buttons that allow the user to enter data into an EditText box. I want all the default functionality of an EditText box except for the pop up of the soft keyboard. the only data to be allowed to enter into the EditText box should be the data from the buttons I have defined. I am trying to suppress the soft keyboard by catching the touch event and returning true. (per the conversation found on this thread )

private OnTouchListener txtTouchListener = new OnTouchListener()
    {
    @Override
    public boolean onTouch(View v, MotionEvent event)
        {
        //Return true to suppress the passing of the event on to the OS
        return true;
        }
    };

The problem is that this method then blocks the long click event from firing. To solve this I can return false and then handle the long click event. However, this then makes the short click bring up the soft keyboard. Also, upon long click not only is the soft keyboard suppressed, but so is the context menu. I am looking for a way to stop the keyboard from appearing on a short (or long) click but keep all other functionality (updating the cursor position on short click, on long click show the EditText context menu, etc.)

Any ideas on this is greatly appreciated!

This thread suggests:

EditText.setInputType(InputType.TYPE_NULL);

Or you set the inputType in the XML Attribute to none .

Not tried it myself though.

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