我试图将TextInputEditText设为只读,但光标快速闪烁,点击被触发.

I tried setting isFocusable = false and isClickable = false.

XML布局:

<com.google.android.material.textfield.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="@string/label_address"
    android:layout_marginTop="@dimen/material_layout_vertical_spacing_between_content_areas"
    style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">

    <com.google.android.material.textfield.TextInputEditText
        android:id="@+id/input_address"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:imeOptions="actionNext"/>

</com.google.android.material.textfield.TextInputLayout>

Code to make read-only:

fun TextInputEditText.disable() {
    isFocusable = false
    isClickable = false
}

什么是使TextInputItemText只读的正确方法?

推荐答案

I usually use setEnabled(boolean) ref link

它能满足您的需要吗?

Kotlin相关问答推荐

将基于注册的服务转换为流

在Jetpack Compose中创建波浪式文本动画:顺序中断问题

我需要后台工作才能使用卡夫卡的消息吗?

如何在数据类中删除空格 (String)?

为什么在jacksonObjectMapper上将DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES设置为false无效?

为什么 Kotlin main 函数需要 @JVMStatic 注解?

Ktor 在 Heroku 上的 CORS 问题,但在本地没有

Android Jetpack Compose:在空的 Compose 活动中找不到 OutlinedTextField (Material3)

在 kotlin 中重载函数时,我在一些非常基本的代码上不断收到类型不匹配

Kotlin 具体类从抽象类和接口扩展而来,接口使用抽象类中实现的方法

如何通过 compose 处理剪切区域?

在 Kotlin 中,::class.simpleName是做什么的?

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

内联函数导致单元测试代码覆盖率报告出错

未为任务启用 Gradle 构建缓存

如何处理 Kotlin 中的异常?

在java代码中使用kotlin库

如何捕获传递给模拟函数的参数并返回它?

API 26 上未显示 Android 通知

用于代码生成的ANTLR工具版本4.7.1与当前运行时版本4.5.3不匹配