- android 进行 段落布局时 需要首行缩进, 虽然可以用html标签但是只是简单的应用,以下是解决方案:
在string.xml文件中
<string name="text_name">\u3000\u3000描述字段 <string>
得到文件中的字符串
String jdsc_text=(String) this.getResources().getString(R.string.text_name);
textview.setText(jdsc_text);
- 改变部分字体的大小和颜色
TextView textView1 = (TextView) findViewById(R.id.textView1);
TextView textView2 = (TextView) findViewById(R.id.textView2);
TextView textView3 = (TextView) findViewById(R.id.textView3);
TextView textView4 = (TextView) findViewById(R.id.textView4);
//两次加大字体,设置字体为红色(big会加大字号,font可以定义颜色)
textView1.setText(Html.fromHtml("北京市发布霾黄色预警,<font color='#ff0000'><big><big>外出携带好</big></big></font>口罩"));
//设置字体大小为3级标题,设置字体为红色
textView2.setText(Html.fromHtml("北京市发布霾黄色预警,<h3><font color='#ff0000'>外出携带好</font></h3>口罩"));
//设置字体大小为58(单位为物理像素),设置字体为红色,字体背景为黄色
textView3.setText("北京市发布霾黄色预警,外出携带好口罩");
Spannable span = new SpannableString(textView3.getText());
span.setSpan(new AbsoluteSizeSpan(58), 11, 16, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
span.setSpan(new ForegroundColorSpan(Color.RED), 11, 16, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
span.setSpan(new BackgroundColorSpan(Color.YELLOW), 11, 16, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
textView3.setText(span);
//两次缩小字体,设置字体为红色(small可以减小字号)
textView4.setText(Html.fromHtml("北京市发布霾黄色预警,<font color='#ff0000'><small><small>外出携带好</small></small></font>口罩"));