简体   繁体   English

如何使用PasswordToggleEnabled将DrawableLeft设置为EditText

[英]How to set a DrawableLeft to an EditText with PasswordToggleEnabled

I've made a TextInputEditText for a PasswordField with a DrawableLeft as an icon, and then i added a PasswordToggleEnabled(true) .. this operation has deleted or hiden my DrawableLeft , Here's my code: 我为一个带有DrawableLeft作为图标的PasswordField创建了一个TextInputEditText ,然后我添加了一个PasswordToggleEnabled(true) ..这个操作已经删除或隐藏了我的DrawableLeft ,这是我的代码:

<android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:passwordToggleContentDescription="Show Password"
        app:passwordToggleEnabled="true"
        app:hintEnabled="false"
        android:id="@+id/signupPasswordlayout"
        app:passwordToggleTint="@color/edittexttint">
        <android.support.design.widget.TextInputEditText
            android:hint="Password"
            android:id="@+id/signupPassword"
            android:drawableLeft="@drawable/ic_password"
            android:drawablePadding="10dp"
            android:inputType="textPassword"
            android:drawableTint="@color/edittexttint"
            android:textSize="15sp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
        </android.support.design.widget.TextInputLayout>

so , is it possible to show both ( PasswordToggle and DrawableLeft ? ) thank you! 那么,是否可以同时显示( PasswordToggleDrawableLeft ?)谢谢!

I'd not seen this exact behavior before, but looking at the source for TextInputLayout , it does attempt to preserve the user-set drawables when it applies the placeholder drawable for the password toggle. 我之前没有看到过这种确切的行为,但是查看TextInputLayout的源代码时,它会尝试在应用占位符drawable进行密码切换时保留用户设置的drawable。 However, like most everything else in the support libraries to which its applicable, it handles them with relative positions - ie, start and end - rather than absolute - left and right . 但是,与其适用的支持库中的大多数其他内容一样,它使用相对位置处理它们 - 即startend - 而不是绝对 - leftright

The support libraries have always been notorious for breaking anything that specifies absolute directions or positions, so it's no surprise that that's the issue here, as well. 支持库一直以打破指定绝对方向或位置的任何东西而臭名昭着,因此这也是问题所在,这也就不足为奇了。

Simply change the attribute you're setting to drawableStart , instead of drawableLeft . 只需将您设置的属性更改为drawableStart ,而不是drawableLeft Keep this in mind, too, for anything else involving a choice of absolute or relative positions and directions with the support libraries. 对于涉及支持库中绝对或相对位置和方向选择的任何其他事项,请记住这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM