Android TextView 个别文字字体颜色格式
来源:互联网 发布:淘宝联盟 提现 手续费 编辑:程序博客网 时间:2024/05/26 15:57
1.简单的办法,用Html来格式化字符
- import android.app.Activity;
- import android.os.Bundle;
- import android.text.Html;
- import android.widget.TextView;
- public class AndroidFronColorTest extends Activity {
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- TextView htmlFormateTextView = (TextView)findViewById(R.id.testTextView);
- String source = "这只是一个测试,测试<u>下划线</u>、<i>斜体字</i>、<font color='red'>红色字</font>的格式";
- htmlFormateTextView.setText(Html.fromHtml(source));
- }
- }
方法2 Spannable
- import android.app.Activity;
- import android.graphics.Color;
- import android.os.Bundle;
- import android.text.Html;
- import android.text.Spannable;
- import android.text.style.BackgroundColorSpan;
- import android.text.style.StyleSpan;
- import android.widget.EditText;
- import android.widget.TextView;
- public class AndroidFronColorTest extends Activity {
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- TextView htmlFormateTextView = (TextView)findViewById(R.id.testTextView);
- String source = "这只是一个测试,测试<u>下划线</u>、<i>斜体字</i>、<font color='red'>红色字</font>的格式";
- htmlFormateTextView.setText(Html.fromHtml(source));
- EditText et = (EditText) findViewById(R.id.textView);
- Spannable sp = (Spannable) et.getText();
- sp.setSpan(new BackgroundColorSpan(Color.RED), 0, 5,
- Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
- sp.setSpan(new StyleSpan(android.graphics.Typeface.BOLD_ITALIC), 6, 11,
- Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
- }
- }
- Android TextView 个别文字字体颜色格式
- Android TextView 个别文字字体颜色格式
- Android TextView 个别文字字体颜色格式
- Android TextView中设定个别文字字体显示格式或者高亮显示
- TextView 设置个别字体颜色
- android TextView怎么设置个别字体颜色并换行?
- Android TextView设置个别字体样式
- Android TextView设置个别字体样式
- Android TextView设置个别字体样式
- Android TextView设置个别字体样式
- Android TextView设置个别字体样式
- 【Android】 TextView设置个别字体样式
- Android TextView设置个别字体样式
- 【Android】 TextView设置个别字体样式
- Android TextView中文字设置超链接、颜色、字体
- Android TextView中文字设置超链接、颜色、字体
- Android TextView中文字设置超链接、颜色、字体
- Android TextView中文字设置超链接、颜色、字体
- 动态编辑母版页(与母版页通信,如修改控件属性等)
- html
- MFC真难学
- 我的选择
- java文件操作
- Android TextView 个别文字字体颜色格式
- 我的笔记
- 学习堆和栈的区别()
- 一个简单的日期操作类
- 抽象类和接口总结
- 学习真好
- 你好
- 第一个
- 把程序作为人生,把人生当作程序