Setting onClickListener to editText

2019-06-07 16:26发布

Hi im trying to add on click listener to editText so i can disable the softkeyboard when user clicks on edittext using this code below, how to do that?

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(edittext.getWindowToken(), 0);

1条回答
时光不老,我们不散
2楼-- · 2019-06-07 16:46

First it needs to be focusable...

<EditText
    ...
    android:inputType="none"
    android:focusable="false"
    ... />

You have to implement it in your code and than just add this to get an click listener...

myEditText.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        // hide the keyboard
        // show own keyboard or buttons
    }
});
查看更多
登录 后发表回答