无法使用passwordToggleEnabled添加drawableStart / drawableLeft

时间:2018-08-02 05:24:05

标签: java android android-studio

我也尝试使用Java代码添加它;

password.setCompoundDrawablesRelativeWithIntrinsicBounds(drawable, 0, 0, 0);

我还搜索了解决此问题的方法,但无济于事,我只找到了drawableStart,它也无法正常工作。

2 个答案:

答案 0 :(得分:1)

editText.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.drawableRight, 0);

尝试:

setCompoundDrawablesWithIntrinsicBounds(left,top,right,bottom)

与之相比:

setCompoundDrawablesRelativeWithIntrinsicBounds

答案 1 :(得分:0)

对我有用:

enter image description here

使用TextInputLayout具有password toggle功能。 如下

 <android.support.design.widget.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:passwordToggleEnabled="true"
    android:hint="enter name"
    app:passwordToggleTint="@color/colorPrimary"
    android:textColorHint="@color/colorPrimary"
    android:layout_marginBottom="100dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintStart_toEndOf="parent">
         <android.support.design.widget.TextInputEditText
             android:drawableLeft="@drawable/share_red"
             android:drawablePadding="10dp"
             android:inputType="numberPassword"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:drawableStart="@drawable/share_red" />

</android.support.design.widget.TextInputLayout>