带有模拟器键盘的Kotlin edittxt.onKeyListener

时间:2019-03-20 16:46:33

标签: android kotlin

我试图将按钮重置为一旦按下键盘上的键即可单击。它适用于硬件键盘,但不适用于仿真器键盘。一个人将如何实现呢?

class MainActivity : AppCompatActivity() {

        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            setContentView(R.layout.activity_main)

            val button = findViewById<Button>(R.id.log_in_button)
            val email = findViewById<EditText>(R.id.email_field)

            button.isClickable = false
            button.alpha = .5f

            email.setOnKeyListener(object : View.OnKeyListener {
                override fun onKey(v: View, keyCode: Int, event: KeyEvent): Boolean {

                    if(event.action == KeyEvent.ACTION_DOWN) {

                        button.isClickable = true
                        button.alpha = 1f
                        return true
                    }

                    return false
                }
            })
}

0 个答案:

没有答案