【问题标题】:How to embed icon inside textfield in android?如何在android的文本字段中嵌入图标?
【发布时间】:2016-07-22 08:46:44
【问题描述】:

我正在尝试实现一个带有眼睛图标的密码字段。
我将<android.support.design.widget.TextInputLayout> 用于动画目的。

然而,眼睛图标继续显示在 EditText 下。

这是我的代码:

<android.support.design.widget.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="5dp"
                android:layout_marginTop="5dp">

                <EditText
                    android:id="@+id/input_password"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="Password"
                    android:inputType="textPassword" />

                <ImageView
                    android:id="@+id/fragment_login_password_visibility"
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:layout_alignRight="@+id/fragment_login_password"
                    android:clickable="true"
                    android:src="@drawable/ic_show_password" />

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

非常感谢任何帮助。

【问题讨论】:

标签: android android-layout compound-drawables


【解决方案1】:

android:drawableLeft="@drawable/ic_show_password" 添加到您的 EditText。
并摆脱 ImageView。

您可以使用复合可绘制对象将图标放在视图的左侧(如我的示例中)、右侧、顶部和/或底部。

【讨论】:

  • 现在图标在inside你的View,而不是outside。 ;)
  • 是的。非常感谢!
猜你喜欢
  • 1970-01-01
  • 2020-02-04
  • 1970-01-01
  • 2012-06-01
  • 2011-03-16
  • 1970-01-01
  • 1970-01-01
  • 2013-10-09
  • 1970-01-01
相关资源
最近更新 更多