android - 禁用 TextInputEditText 时禁用密码切换 ImageButton

标签 android android-layout android-textinputlayout android-textinputedittext

当 TextInputLayout 的 app:passwordToggleEnabled 属性设置为 true 且 TextInputEditText 的 android:enabled 属性设置为 false 时,如何防止密码切换 ImageButton可点击?

<com.google.android.material.textfield.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="24dp"
    android:hint="@string/password"
    app:hintAnimationEnabled="true"
    app:passwordToggleEnabled="true">

    <com.google.android.material.textfield.TextInputEditText
        android:id="@+id/edit_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textPassword"
        android:maxLength="32"
        android:maxLines="1"
        android:enabled="false"/>

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

Issue demo

这是错误还是预期的行为?

最佳答案

就像我在评论中提到的那样,解决您的问题的一个简单方法是将 TextInputLayout 的 setEnabled 设置为 false 而不是 TextInputEditText。由于 TextInputLayout 包含 TextInputEditText,因此整个布局将被禁用。这是一个小演示:

TextInputLayout textInputLayout = findViewById(R.id.textInputLayout);

if(someCondition){
    textInputLayout.setEnabled(false);
}

希望这对您有所帮助.. 编码愉快!

关于android - 禁用 TextInputEditText 时禁用密码切换 ImageButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54836514/

相关文章:

android - 在没有GPS的Android 8.1中获取WIFI SSID

android - 虚拟设备的cpu数被强制为1

android - 从布局创建具有多个 View 的 RecyclerView

android - 如何将全局自定义样式应用于android.support.design.widget.TextInputEditText?

android - * native react * |使用未知 URL 链接 => canOpenURL(url)?

Android 在 AlertDialog 中验证 EditText

android - 两个方向的 ScrollView

Android 防止双击 Spinner

android - 如何设置TextInputLayout大纲框 float 提示背景色

android - AutoCompleteTextView - 如何删除顶部和底部的边距?