gpt4 book ai didi

android - 如何在 "TextInputLayout"的右端动态添加一个 drawable?

转载 作者:行者123 更新时间:2023-12-05 00:09:09 31 4
gpt4 key购买 nike

我正在尝试做类似这个例子的东西:

Screenshot of a user name text field with a check suffix icon

我希望在我从服务器验证用户名时显示可绘制对象。

我正在使用 Material Design 文本输入字段和 EditText。是的,我可以用一个简单的 EditText 和一个 ImageView 来完成,但我想使用标准元素。

我看过官方文档,有一种方法可以使用 XML 在右上角添加图像,但我想以编程方式添加它。

最佳答案

使用setEndIconDrawable方法:

    textInputLayout.setEndIconDrawable(R.drawable.xxxx);
textInputLayout.setEndIconMode(TextInputLayout.END_ICON_CUSTOM);

或在布局中:

  <com.google.android.material.textfield.TextInputLayout
app:endIconDrawable="@drawable/xxxxx"
app:endIconMode="custom"

enter image description here

更多信息在 official doc .

关于android - 如何在 "TextInputLayout"的右端动态添加一个 drawable?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62574021/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com