首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

无法添加drawableStart/drawableLeft使用passwordToggleEnabled离开

问题描述:

无法添加drawableStart/drawableLeft使用passwordToggleEnabled离开

回答:

在Android开发中,drawableStart或drawableLeft属性用于在EditText控件的文本框中添加一个可绘制的图标,而passwordToggleEnabled属性用于在密码输入框中添加一个切换密码可见性的图标。然而,有时候在使用passwordToggleEnabled属性时,无法同时添加drawableStart或drawableLeft属性,导致图标无法显示。

这个问题可能是由于TextInputLayout控件的特性所致。TextInputLayout是一个用于包装EditText的布局容器,它提供了一些额外的功能,如浮动标签和密码可见性切换。然而,由于TextInputLayout的实现方式,导致无法直接在EditText上添加drawableStart或drawableLeft属性。

解决这个问题的方法是使用TextInputEditText控件替代EditText,并将其放置在TextInputLayout中。TextInputEditText是TextInputLayout的一个子类,它继承了EditText的所有功能,并且可以正常显示drawableStart或drawableLeft属性。

以下是一个示例代码:

代码语言:xml
复制
<com.google.android.material.textfield.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <com.google.android.material.textfield.TextInputEditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:drawableStart="@drawable/ic_icon"
        android:drawableLeft="@drawable/ic_icon"
        android:inputType="textPassword"
        android:passwordToggleEnabled="true" />

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

在上述示例中,我们使用了TextInputLayout包装了一个TextInputEditText,并在TextInputEditText上同时设置了drawableStart和passwordToggleEnabled属性。这样就可以同时显示图标和密码可见性切换按钮。

推荐的腾讯云相关产品:腾讯云移动推送(https://cloud.tencent.com/product/umeng_push)、腾讯云移动分析(https://cloud.tencent.com/product/ma)、腾讯云移动测试(https://cloud.tencent.com/product/mtc)。

希望以上信息对您有所帮助!

页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

没有搜到相关的合辑

领券