我试图在Kotlin中以编程方式禁用EditText,但我找不到任何方法.我try 了以下不起作用的代码:

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

panEditText.enabled = false //No such method found

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

推荐答案

You should use isEnabled.

Set the enabled state of this view.

 panEditText.isEnabled =false

Method Overview

@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();
        }
    }

Kotlin相关问答推荐

为什么在Spring中,对事务性方法调用的非事务方法调用仍然在事务中运行?

如何确保Kotlin子类已完成初始化?

Kotlin 海峡没有结束

Kotlin:类型不匹配:推断的类型已运行,但应等待

数据流弹性模板失败,出现错误&未知非复合转换urn";

Spring Boot Kotlin 数据类未使用 REST 控制器中的默认值初始化

区分函数和扩展

如何缩短 MaterialTheme.colors.primary?

如何限制 Kotlin 中的枚举?

如果不为空,则为 builder 设置一个值 - Kotlin

为什么我们在 kotlin 中需要 noinline?

Android 导航组件 - 向上导航打开相同的片段

如何退出 Kotlinc 命令行编译器

Kotlin默认使用哪种排序?

Spring Boot:更改属性占位符符号

Android 上的 Kotlin:将map到list

IllegalStateException:function = , count = 3, index = 3

Kotlin - 如何获取注释属性值

Kotlin反射不可用

Kotlin 中的限制函数