You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Android中修改密码显示/隐藏的眼睛切换图标

endIconDrawable 配置不生效修复方案

app:endIconDrawable是Material Design组件库中TextInputLayout的专属属性,单独配置该属性默认不会生效,常见修复步骤如下:

  • 确认属性挂载位置正确
    该属性必须配置在TextInputLayout节点上,不能配置在内部嵌套的TextInputEditText或普通EditText节点上。
  • 补充endIconMode配置
    必须同步添加app:endIconMode="custom"属性,指定尾部图标为自定义模式,配置示例:
    <com.google.android.material.textfield.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        <!-- 必须添加的模式配置 -->
        app:endIconMode="custom"
        <!-- 你的自定义图标配置 -->
        app:endIconDrawable="@drawable/custom_password_selector">
    
        <com.google.android.material.textfield.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="请输入内容"/>
    
    </com.google.android.material.textfield.TextInputLayout>
    
    如果你的使用场景是密码可见/隐藏切换,也可以将app:endIconMode设置为password_toggle,自定义图标会自动覆盖系统默认的切换图标。
  • 验证资源合法性
    检查@drawable/custom_password_selector是否为合法的drawable资源,selector文件的格式、引用的颜色/图片资源是否存在,没有语法错误。
  • 检查组件库版本
    确认项目依赖的com.google.android.material:material版本不低于1.1.0,该属性从1.1.0版本开始正式提供支持。

内容的提问来源于stack exchange,提问作者Partha

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.04 03:03:00