TextView显示文本控件

来源:互联网 发布:网络硬盘录像机多少钱 编辑:程序博客网 时间:2024/05/18 11:14

TextView主要是在android中实现文字说明等功能。主要的功能如下:
显示丰富的文本(URL,字体大小,颜色等)
在TextView中预定了一些类似HEML的标签,通过标签可以使TextView控件显示不同颜色,大小,字体等。
设置颜色和字体
设置大号
设置大号
\ 斜体,粗体
链接地址
插入图片

案例:
main.xml文件

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    >    <TextView        android:id="@+id/tv_one"        android:layout_width="match_parent"        android:layout_height="wrap_content"         />     <TextView        android:id="@+id/tv_two"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:autoLink="all"         /></LinearLayout>

Activity文件

package text.demo;import android.app.Activity;import android.os.Bundle;import android.text.Html;import android.text.method.LinkMovementMethod;import android.widget.TextView;public class TextViewDemoActivity extends Activity {    /** Called when the activity is first created. */    private TextView tv_one;    private TextView tv_two;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);        tv_one=(TextView)findViewById(R.id.tv_one);        tv_two=(TextView)findViewById(R.id.tv_two);        String text1= "<font color = 'red'><i>  林肯公园  </i></font><br/>";        text1+="    <  a href='  http://www.baidu.com'     >   百度     </a></br>";        tv_one.setText(Html.fromHtml(text1));        tv_one.setMovementMethod(LinkMovementMethod.getInstance());        String text2="我的网站:http://baidu.com        "       ;        text2+="   我的电话:3233223    ";        tv_two.setMovementMethod(LinkMovementMethod.getInstance());    }} 
0 0
原创粉丝点击