Android(安卓)代码中设置EditText的hint字体大小
16lz
2021-01-26
<?xml version=”1.0” encoding=”utf-8”?>
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:background=”#ffffff”
android:orientation=”vertical” >
android:id=”@+id/editText1”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:hint=”我是测试hint”
android:textColor=”#f00”
android:textSize=”25sp”
android:ems=”10” >
android:layout_height=”match_parent”
android:background=”#ffffff”
android:orientation=”vertical” >
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:hint=”我是测试hint”
android:textColor=”#f00”
android:textSize=”25sp”
android:ems=”10” >
这是一个普通的线性布局里面套了个Edittext 如下 :设置了文字大小为25sp 但是他的hint值也是25sp 如果我们想改变hint字体大小而不改变文字的大小怎么办呢
这就需要再代码中设置了 代码如下 还是这个布局
public class HintActivity extends Activity{
EditText editText;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.hint);
editText=(EditText) findViewById(R.id.editText1);
SpannableString ss = new SpannableString(“我是测试hint”);//定义hint的值
AbsoluteSizeSpan ass = new AbsoluteSizeSpan(15,true);//设置字体大小 true表示单位是sp
ss.setSpan(ass, 0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
editText.setHint(new SpannedString(ss));
}
}
看这个时候hint字体大小变小了为我们设置的15sp尽管再xml文件中设置了字体大小再看输入的文字大小还是25sp没
有变化
更多相关文章
- Android状态栏透明方法,与工具栏颜色一致
- AndroidManifest.xml中android:label标签的使用
- Android中的搜索框(SearchView)的功能和用法
- 【Android】TabLayout 自定义指示器 Indicator 样式
- Android录音应用实例教程
- android 倒计时的控件,以动画的形式平滑的完成数字的过度
- 【Android】listview选中行字体变大
- android开发――ListView组件
- Android(安卓)Studio开发界面自定义,更有利于开发