热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

TextView字体大小及颜色设置

TextView设置文字大小及颜色:1.1)通过xml配置<TextViewandroid:layout_

TextView设置文字大小及颜色:

  1.1)通过xml配置

  

    android:layout_

    android:layout_

    android:textColor="#FF0000"

    android:textSize="18sp"/>

  1.2)通过代码设置(方式一)

TextView textView = new TextView(this);
textView.setTextColor(Color.RED);
textView.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 18, getResources().getDisplayMetrics()));
// textView.setText(Html.fromHtml("TextView")); // 该方式不支持设置字体大小

      1.3)通过代码设(方式二,支持字体大小与颜色)

String text = "年收益率:5.88%";
SpannableString spanText = new SpannableString(text);
spanText.setSpan(new ForegroundColorSpan(Color.BLACK), 0, 5, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
spanText.setSpan(new TextAppearanceSpan(this, R.style.text_style), 5, text.length() - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
spanText.setSpan(new ForegroundColorSpan(Color.RED), text.length() - 1, text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
mTextView.setText(spanText);


Style文件:

 


推荐阅读
author-avatar
晴活的比较迷-茫m
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有