我也尝试使用Java代码添加它;
password.setCompoundDrawablesRelativeWithIntrinsicBounds(drawable, 0, 0, 0);
我还搜索了解决此问题的方法,但无济于事,我只找到了drawableStart,它也无法正常工作。
答案 0 :(得分:1)
editText.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.drawableRight, 0);
尝试:
setCompoundDrawablesWithIntrinsicBounds(left,top,right,bottom)
与之相比:
setCompoundDrawablesRelativeWithIntrinsicBounds
答案 1 :(得分:0)
对我有用:
使用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>