android - 使复选框不可由用户编辑,但可通过编程方式编辑

标签 android checkbox

我想限制用户更改它。我应该能够以编程方式更改它,但不能由用户更改。我试过了,可编辑,可点击出来都不行。

应该怎么做?

 <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:baselineAligned="false"
        android:paddingLeft="8dip"
        android:paddingRight="8dip">

        <androidx.appcompat.widget.AppCompatCheckBox
            android:id="@+id/flight_origin_date"
            style="@style/InputCheckBox"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:text="@string/new_order_flight_origin_date"
            android:visibility="visible"
            android:layout_weight="1"
            android:layout_marginBottom="0dp"
            app:buttonTint="@color/i6_teal" />

    </LinearLayout>

最佳答案

请在androidx.appcompat.widget.AppCompatCheckBox 中将以下两个字段设置为false

android:clickable="false"
android:focusable="false"

关于android - 使复选框不可由用户编辑,但可通过编程方式编辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59054455/

相关文章:

java - Android - 如何在 View 组内设置 subview

javafx - 未选中复选框时如何停止转换javafx

android - Espresso 测试失败

android - 是否有可能与 ATG(艺术科技集团)合作开发 Android 系统?

android - 如何为手势保留 Android Q 中的 Activity 左侧

非根设备上的Android用户空间文件系统驱动程序?

c# - Javascript 函数中复选框的值

apache-flex - Datagrid 中的 Flex CheckBox

ruby-on-rails - Rails check_box_tag 设置为默认值

javascript - HTML - 在本地存储复选框值并检索