Android TextView 个别文字字体颜色格式
1.简单的办法,用Html来格式化字符
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));
- }
- }
http://ghostfromheaven.iteye.com/blog/751099 转自