没有键盘视图的自定义键盘不建议使用

问题描述

所以我想要一个没有高级UI的简单键盘。它必须在一个Activity中膨胀。我不想使用android EditText。这很简单

enter image description here

然后我的InputService类具有以下字段。

class MyIMService : InputMethodService(),View.OnClickListener {
    override fun onCreateInputView(): View {
        val myKeyboardView: View = layoutInflater.inflate(R.layout.layout_keyboard,null)

        val key0: TextView = myKeyboardView.findViewById(R.id.key_0)
        val key1: TextView = myKeyboardView.findViewById(R.id.key_1)
        val key2: TextView = myKeyboardView.findViewById(R.id.key_2)
        val key3: TextView = myKeyboardView.findViewById(R.id.key_3)
        val key4: TextView = myKeyboardView.findViewById(R.id.key_4)
        val key5: TextView = myKeyboardView.findViewById(R.id.key_5)
        val key6: TextView = myKeyboardView.findViewById(R.id.key_6)
        val key7: TextView = myKeyboardView.findViewById(R.id.key_7)
        val key8: TextView = myKeyboardView.findViewById(R.id.key_8)
        val key9: TextView = myKeyboardView.findViewById(R.id.key_9)
        val keyAster: TextView = myKeyboardView.findViewById(R.id.key_asterisk)
        val keyHash: TextView = myKeyboardView.findViewById(R.id.key_hash)


        key0.setOnClickListener(this)
        key1.setOnClickListener(this)
        key2.setOnClickListener(this)
        key3.setOnClickListener(this)
        key4.setOnClickListener(this)
        key5.setOnClickListener(this)
        key6.setOnClickListener(this)
        key7.setOnClickListener(this)
        key8.setOnClickListener(this)
        key9.setOnClickListener(this)
        keyAster.setOnClickListener(this)
        keyHash.setOnClickListener(this)

        return myKeyboardView
    }

    override fun onClick(v: View) {
        //handle all the keyboard key clicks here
        val ic = currentInputConnection
        if (v is TextView) {
            val clickedKeyText: String = v.text.toString()
            ic.commitText(clickedKeyText,1)
        }
    }

    companion object {
        private const val TAG = "MyIMService"
    }
}

我只想知道如何使服务膨胀提供的布局?还是有什么方法可以将服务与布局连接起来?谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...