android开发EditText的Hint字体默认样式和下载字体样式的适配问题。

在Android开发中,遇到EditText的Hint字体样式问题,本文将探讨默认样式与自定义字体样式的适配,通过实例代码解析解决Hint字体显示问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

      紧张了几个月的奋战终于项目到了测试阶段,真是泪奔啊,回想这段时间的地狱生涯 真实汗颜啊~~~~,闲话不多说了,看图说话,


问题,相信这张图片已经展示的很明白了

下来在来看看我的代码

<EditText
    android:id="@+id/account_et"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@+id/account_iv"
    android:layout_centerVertical="true"
    android:background="@null"
    android:singleLine="true"   
    android:hint="请输入帐号"
    android:textColorHint="@color/color_b0b0b0"
android:textSize="13sp" />

<EditText
    android:id="@+id/password_et"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@+id/password_iv"
    android:background="@null"
    android:singleLine="true"
    android:hint="请输入密码"
    android:inputType="textPassword"
  android:textColorHint="@color/color_b0b0b0" android:textSize="13sp" />
<EditText
    android:id="@+id/password_et_again"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:layout_toRightOf="@+id/password_iv_again"
    android:background="@null"
    android:singleLine="true"
    android:hint="请再次输入密码"
    android:textColorHint="@color/color_b0b0b0"
    android:textSize="13sp" />
下面的代码都是一样的,我就没有贴出来。看看这个代码貌似没有什么问题,
平常也一直都是这样写的。其实这样写并没有错,只是我们这样写hint的字体是
android系统默认的,如果我们在给手机上面下载一个字体样式,就会出现上面图片显示的问题,
新下载的字体样式应用不到hint上面的字体样式。hint的字体还是原来系统默认的字体,测试后发现只要加上
android:inputType="textPassword"
这行代码就会出现问题。
要想解决这样的问题,让hint的字体也显示成我们下载的字体样式。其实也不难 下面这两行代码也许可以解决,
在onCreate方法出初始化EditText控件时候 加上着两行就ok
mPasswordEt.setTypeface(Typeface.DEFAULT);
mPasswordEt.setTransformationMethod(new PasswordTransformationMethod());

加上着两行就ok
图就不贴了
想要给那个控件添加 也是同样的方法,好了 然后运行一下程序,换一个下载的字体样式
会发现显示都是一样的了





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值