展会信息港展会大全

Android TextView 文本的不同颜色
来源:互联网   发布日期:2015-11-15 10:12:40   浏览:2463次  

导读:面试其中有一道题是:TextView中文本的颜色设置?例如:中软国际,其中中软为红色,国际为绿色。方法一:LinearLayout android:layout_width=fill_parent android:layout_height=wrap_content and......

面试其中有一道题是:

TextView中文本的颜色设置?例如:中软国际,其中中软为红色,国际为绿色。

方法一:

<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>

方法二:

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();

}

}

PS:凡是不要想的太复杂。简简单单就好

赞助本站

人工智能实验室

相关热词: 颜色 文本

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港