zoukankan      html  css  js  c++  java
  • Android中对同一个TextView设置不同字体样式

    这个只是做一个笔记,详情见代码:

    代码中的注释也有说明。

    TextView textView = (TextView) findViewById(R.id.textView1);
    		SpannableStringBuilder sb = new SpannableStringBuilder("abcdefghijklmnopqrst."); // 包装字体内容
    		ForegroundColorSpan fcs = new ForegroundColorSpan(getResources().getColor(R.color.yellow_orange)); // 设置字体颜色
    		StyleSpan bss = new StyleSpan(android.graphics.Typeface.BOLD); // 设置字体样式
    		AbsoluteSizeSpan ass = new AbsoluteSizeSpan(140);  // 设置字体大小
    		
    		sb.setSpan(fcs, 0, 10, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
    		sb.setSpan(bss, 0, 20, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
    		sb.setSpan(ass, 0, 5, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    		textView.setText(sb);
    运行结果如下:



  • 相关阅读:
    css 旋转
    html 旋转
    链表和数组的区别
    hashmap
    【java开发系列】—— 自定义注解
    java不确定参数个数方法例子
    mysql 删除
    linux下常用命令
    php的几种算法(转载)
    数据容器
  • 原文地址:https://www.cnblogs.com/fengju/p/6336141.html
Copyright © 2011-2022 走看看