04-文本显示组件 TextView

目标:

      掌握文本显示组件的配置和使用

      掌握文本显示组件的继承结构

      掌握文本显示组件的基本属性和操作方法

    对于文本显示组建而言主要的目的是静态的显示一些文字,就相当与完成了一些标签的显示功能

android.widget.TextView类是View直接子类,所以在本组件之中也会提供更多的属性和方法

        新建项目android-2

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

    android:orientation="vertical" >


    <TextView

        android:id="@+id/mytext1"

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:textColor="#FFF000"                   //字体颜色

        android:textSize="50px"                            //字体大小(必须有单位)

        android:text="大连北良科技(DLBL)" />


</LinearLayout>

android所有的组建都可以设置其大小,但是在设置大小的时候都要有单位:

      px: 像素

      dip: 依赖于设备的像素

      sp:带比例的像素

      pt:点

      in:英尺

      mm:毫米

 

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

    android:orientation="vertical" >


    <TextView

        android:id="@+id/mytext2"

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:textColor="#FFF000"       //文字颜色

        android:layout_margin="30px"     //距离上面 左面的距离

        android:layout_marginTop="10px"        //距离上面距离

        android:text="网址:www.baidu.com"   //默认显示文字

        />


</LinearLayout>

//---------------------------------------------------------------------------------

 

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

    android:orientation="vertical" >


    <TextView

        android:id="@+id/mytext4"

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:background="@drawable/logo"

        android:textColor="#000000"

        android:textStyle="bold"

        android:text="这是在背景上的文字信息"

        />


</LinearLayout>

//----------------------------------------------------------------------------------

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

    android:orientation="vertical" >


    <TextView

        android:id="@+id/mytext4"

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:background="@drawable/logo"

        android:autoLink="web"                        //增加链接

        android:text="网址:www.baidu.com"    //显示的带链接的网址

        />


</LinearLayout>

 

了解了基本使用之后,现在也会出现一个问题,如果说要在一个项目之中定义多个文本组件,这可能会存在着许多重复的配置属性,所以在android开发中也可以使用样式表文件进行统一的属性配置。

   样式表文件styles放在values包下面

   例如定义样式表--styles.xml

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值