TextView中文本的颜色设置?例如:中软国际,其中中软为红色,国际为绿色。
方法一:
- <span style="font-size:18px;"><LinearLayout
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal">
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="中软"
- android:textColor="#FFFF0000" />
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="国际"
- android:textColor="#FF00FF00" />
- </LinearLayout></span>
方法二:
- <span style="font-size:18px;">package me.lechao;
- import android.app.Activity;
- import android.os.Bundle;
- import android.text.Html;
- import android.widget.TextView;
- public class MainActivity extends Activity {
- /** 利用HTML语言,改变文字颜色 */
- private void init() {
- String str = "<font color='red'>中软</font>"
- + "<font color= 'green'>国际</font>";
- TextView tv = new TextView(this);
- tv.setText(Html.fromHtml(str));
- }
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- init();
- }
- }</span>
PS:凡是不要想的太复杂。简简单单就好。
原文链接: http://blog.csdn.net/bys0201/article/details/7246313