【问题标题】:How to show left drawable in AppCompatEditText with passwordToggleEnabled?如何使用 passwordToggleEnabled 在 AppCompatEditText 中显示左侧可绘制对象?
【发布时间】:2017-07-07 18:01:10
【问题描述】:

添加 passwordToggleEnabled="true" 时我有一个 AppCompatEditText,我的左侧可绘制对象消失了。可能是什么原因?

密码编辑文本代码:

<android.support.design.widget.TextInputLayout
        app:passwordToggleEnabled="true"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:layout_marginBottom="8dp"
        android:layout_marginTop="8dp"
        app:hintEnabled="false"
        app:passwordToggleEnabled="true">
            <android.support.v7.widget.AppCompatEditText
                android:id="@+id/input_password"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:drawablePadding="20dp"
                android:inputType="textPassword"
                android:hint="@string/password_hint"
                android:paddingLeft="15dp"
                android:theme="@style/EditTextTheme"/>
</android.support.design.widget.TextInputLayout>

EditText 可绘制代码:

_passwordEditText.setCompoundDrawablesWithIntrinsicBounds(passwordIcon, null, null, null);

使用 app:passwordToggleEnabled="true" :

没有它:

编辑:我可以在顶部和底部设置可绘制对象,但它不适用于左右。

【问题讨论】:

  • 解决了你的问题吗?我有同样的问题?
  • 不...我创建了一个解决方法,分别拥有图标。如果你解决了,请发布解决方案

标签: android android-layout android-edittext


【解决方案1】:

试试这个,而不是为现有的drawable设置null,而是获取drawable并将你的设置在左侧。

Drawable[] drawables = _passwordEditText.getCompoundDrawables();

_passwordEditText.setCompoundDrawablesWithIntrinsicBounds(passwordIcon, drawables[1], drawables[2], drawables[3]);

(来源:来自 Stack Overflow 文档的示例“自定义编辑文本中的图标或按钮及其操作和单击侦听器”;版权所有 2017 年 Muthukrishnan Rajendran;根据 CC BY-SA 3.0 许可。archive of the full Stack Overflow Documentation content 可以可在archive.org 上找到,其中该示例按主题ID 5843 和示例ID 32126 进行索引。)

【讨论】:

  • 感谢 Muthukrishnan,但它对我不起作用。我可以在顶部和底部设置可绘制对象,但它不适用于左右。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多