android:hint 如何设置字体的大小

本文介绍了如何在Android中自定义EditText控件的提示信息样式,包括使用不同颜色及调整字体大小的方法。通过html标签和特定API实现更灵活的设计。

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

android:hint是显示默认信息的属性,但是这个属性目前(从我查的资料)只能设置颜色主要是两种方式

1、android:textColorHint=""

2、setHintTextColor(colors);

其实我们也可以用html的方式来设置这个属性毕竟都是String

setHint(Html.fromHtml("<font color=\"#cbccd1\">请输入您的手机号</font>"));


同样我们可以通过标签来设置字体的大小

setHint(Html.fromHtml("<font color=\"#cbccd1\"><small>请输入您的手机号</small></font>"));

这个small标签就是控制字体的大小

如果你嫌字体还不够小,可以多设置几个small

setHint(Html.fromHtml("<font color=\"#cbccd1\"><small><small>请输入您的手机号</small></small></font>"));

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:padding="20dp" android:gravity="center"> <ImageView android:layout_width="100dp" android:layout_height="100dp" android:src="@mipmap/logo" android:layout_gravity="center_horizontal" android:layout_marginBottom="30dp"/> <com.google.android.material.textfield.TextInputLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="10dp"> <com.google.android.material.textfield.TextInputEditText android:id="@+id/et_username" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="用户名" android:inputType="text" android:maxLines="1"/> </com.google.android.material.textfield.TextInputLayout> <com.google.android.material.textfield.TextInputLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="20dp"> <com.google.android.material.textfield.TextInputEditText android:id="@+id/et_password" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="密码" android:inputType="textPassword" android:maxLines="1"/> </com.google.android.material.textfield.TextInputLayout> <CheckBox android:id="@+id/cb_remember" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="记住密码" android:layout_gravity="start" android:layout_marginBottom="10dp"/> <CheckBox android:id="@+id/cb_auto_login" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="自动登录" android:layout_gravity="start" android:layout_marginBottom="20dp"/> <Button android:id="@+id/btn_login" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="登录" android:backgroundTint="@color/purple_500" android:textColor="@color/white"/> <ProgressBar android:id="@+id/progress_bar" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:visibility="gone" android:layout_marginTop="20dp"/> </LinearLayout> 美化
06-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值