0

我正在尝试制作一个应该接受来自用户的文本输入的自定义视图(我不能使用 EditText)自定义视图适用于软键盘,但它不接收来自物理键盘的输入。我显示键盘和请求专注于触摸

override fun onTouchEvent(event: MotionEvent): Boolean {
    super.onTouchEvent(event)
    if (event.action == MotionEvent.ACTION_DOWN) {
        val imm: InputMethodManager = context
            .getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
        imm.showSoftInput(this, InputMethodManager.SHOW_FORCED)
        requestFocus()
    }
    return true
}

我正在覆盖 onCreateInputConnection

override fun onCreateInputConnection(outAttrs: EditorInfo): InputConnection? {
    val fic = MyInputConnection(this)
    outAttrs.actionLabel = null
    outAttrs.inputType = InputType.TYPE_CLASS_NUMBER
    outAttrs.imeOptions = EditorInfo.IME_ACTION_DONE
    return fic
}
4

0 回答 0