TextView显示文本控件

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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值