我正试图让编辑文本在接收触摸输入的同时,不接收焦点(带来软键盘和闪烁的光标)。
很显然,现在如果我尝试使用setFocusable(false)和setFocusableInTouchMode(false)或setEnabled(false)等方法,它将不会接收任何触摸输入。
我该如何解决这个问题?
更新。
editText = (EditText) = layout.findViewById(R.id.edittext);
editText.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
我想如果你设置OnTouchListener(),并override onTouch()返回true,应该可以工作。
你可以通过在布局中的任何视图上调用ontouch方法来移除。
val eventDown = MotionEvent.obtain(0, 20, MotionEvent.ACTION_DOWN, 0f, 0f, 0)
frameLayView.onTouchEvent(eventDown)
val eventUp = MotionEvent.obtain(0, 20, MotionEvent.ACTION_UP, 0f, 0f, 0)
frameLayView.onTouchEvent(eventUp)