如何启用以前禁用的EditText编辑功能?

时间:2018-07-19 08:31:38

标签: android-studio kotlin android-edittext

This video显示了界面的正确操作:单击“检查...”按钮后,EditText字段的颜色更改,并且其焦点,可单击性等都被禁用。即,该字段变为TextView。 Frag5_Settings.kt类中的hideKeyboard()函数负责此(here code of this and some related classes is laid out)。

override fun hideKeyboard(internalConst: Int) {
    when (internalConst) {
        mThisPresenter.SERVERS_ADDRESS -> {
            tilServersAddress.backgroundColor = Color.GRAY
            etServersAddress.isFocusable = false
            etServersAddress.isLongClickable = false
            etServersAddress.isClickable = false
            etServersAddress.isCursorVisible = false
            hideKeyboard(etServersAddress)
        }
        mThisPresenter.DEVICES_ID -> {
            tilDevicesId.backgroundColor = Color.GRAY
            etDevicesId.isFocusable = false
            etDevicesId.isClickable = false
            etDevicesId.isLongClickable = false
            etDevicesId.isCursorVisible = false
            hideKeyboard(etDevicesId)
        }
    }
}

此外,当您单击“更改...”按钮时,预期TextView的字段将再次获得编辑功能(返回到EditText),但这没有发生(see this video)。光标和键盘不出现。 Frag5_Settings.kt类中的openKeyboardForFields()函数负责此操作:

override fun openKeyboardForFields(internalConst: Int) {
    when(internalConst){
        mThisPresenter.SERVERS_ADDRESS -> {
            tilServersAddress.backgroundColor = Color.WHITE
            etServersAddress.isFocusable = true
            etServersAddress.isClickable = true
            etServersAddress.isLongClickable = true
            etServersAddress.isCursorVisible = true
            etServersAddress.setSelection(etServersAddress.text.lastIndex)
            etServersAddress.requestFocus()
            (context?.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager)
                    .showSoftInput(etServersAddress, 0)
        }
        mThisPresenter.DEVICES_ID -> {
            tilDevicesId.backgroundColor = Color.WHITE
            etDevicesId.isFocusable = true
            etDevicesId.isClickable = true
            etDevicesId.isLongClickable = true
            etDevicesId.isCursorVisible = true
            etDevicesId.setSelection(etDevicesId.text.lastIndex)
            etDevicesId.requestFocus()
            (context?.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager)
                    .showSoftInput(etDevicesId, 0)
        }
    }
}

但是,此功能无法正常工作。如何解决?

0 个答案:

没有答案