📜  当edittext为空时禁用按钮kotlin代码示例

📅  最后修改于: 2022-03-11 14:53:34.095000             🧑  作者: Mango

代码示例1
editText1.addTextChangedListener(object: TextWatcher {
        override fun onTextChanged(s:CharSequence, start:Int, before:Int, count:Int) {
            if (s.toString().trim({ it <= ' ' }).isEmpty())
            {
                button.setEnabled(false)
            }
            else
            {
                button.setEnabled(true)
            }
        }
        override fun beforeTextChanged(s:CharSequence, start:Int, count:Int,
                              after:Int) {
            // TODO Auto-generated method stub
        }
        override fun afterTextChanged(s: Editable) {
            // TODO Auto-generated method stub
        }
    })