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

问题描述

所以我想要一个没有高级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 (将#修改为@)