无法在kotlin android中以编程方式禁用EditText

时间:2018-03-31 18:04:00

标签: android kotlin

我尝试在EditText中以编程方式禁用Kotlin,但我找不到任何方法。我尝试下面没有工作的代码:

panEditText.focusable = false //Requires API 26 and above.

panEditText.enabled = false //No such method found

如何在EditText编程语言中禁用Kotlin

1 个答案:

答案 0 :(得分:7)

您应该使用 isEnabled

  

设置此视图的启用状态。

 panEditText.isEnabled =false

方法概述

@android.view.RemotableViewMethod
    @Override
    public void setEnabled(boolean enabled) {
        if (enabled == isEnabled()) {
            return;
        }

        if (!enabled) {
            // Hide the soft input if the currently active TextView is disabled
            InputMethodManager imm = InputMethodManager.peekInstance();
            if (imm != null && imm.isActive(this)) {
                imm.hideSoftInputFromWindow(getWindowToken(), 0);
            }
        }

        super.setEnabled(enabled);

        if (enabled) {
            // Make sure IME is updated with current editor info.
            InputMethodManager imm = InputMethodManager.peekInstance();
            if (imm != null) imm.restartInput(this);
        }

        // Will change text color
        if (mEditor != null) {
            mEditor.invalidateTextDisplayList();
            mEditor.prepareCursorControllers();

            // start or stop the cursor blinking as appropriate
            mEditor.makeBlink();
        }
    }