如何在 Android 中将 inputType 设置为 textPassword 的 EditText 样式提示
How to style hint for EditText with inputType set to textPassword in Android
当我在我的 EditText 中设置 inputType=textPassword
时,hint
的文本样式发生了变化。请看这张图片:
两个 EditText 具有相同的 XML,但上部的 inputType
设置为 textPassword
。
如何让它们看起来一样?
以编程方式设置默认的 Edittext 字体
password.setTypeface(Typeface.DEFAULT);
问题是文本设置字体。
Tip: By default, when you set an EditText element to use the
"textPassword" input type, the font family is set to monospace, so you
should change its font family to "sans-serif" so that both text fields
use a matching font style.
更多详情请参考这篇link,
Try
在EditText inputType 中设置为textPassword 字体会改变
将 TextInputLayout 用于 EditText 密码字段
试试这个代码:
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hintEnabled="false"
app:passwordToggleEnabled="true">
<EditText
android:id="@+id/input_password"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/white"
android:drawableLeft="@drawable/ic_password"
android:drawableStart="@drawable/ic_password"
android:hint="@string/password"
android:imeOptions="actionDone"
android:inputType="textPassword"
android:textColor="@color/floating_text_color_accent"
android:textSize="@dimen/text_size_small" />
</android.support.design.widget.TextInputLayout>
当我在我的 EditText 中设置 inputType=textPassword
时,hint
的文本样式发生了变化。请看这张图片:
两个 EditText 具有相同的 XML,但上部的 inputType
设置为 textPassword
。
如何让它们看起来一样?
以编程方式设置默认的 Edittext 字体
password.setTypeface(Typeface.DEFAULT);
问题是文本设置字体。
Tip: By default, when you set an EditText element to use the "textPassword" input type, the font family is set to monospace, so you should change its font family to "sans-serif" so that both text fields use a matching font style.
更多详情请参考这篇link, Try
在EditText inputType 中设置为textPassword 字体会改变 将 TextInputLayout 用于 EditText 密码字段
试试这个代码:
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hintEnabled="false"
app:passwordToggleEnabled="true">
<EditText
android:id="@+id/input_password"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/white"
android:drawableLeft="@drawable/ic_password"
android:drawableStart="@drawable/ic_password"
android:hint="@string/password"
android:imeOptions="actionDone"
android:inputType="textPassword"
android:textColor="@color/floating_text_color_accent"
android:textSize="@dimen/text_size_small" />
</android.support.design.widget.TextInputLayout>