Android UI控件之TextView

TextView


前言:

TextView主要用于字体显示,其继承于View类,TextView控件的功能时想用户显示文本的内容,但不允许编辑。

而其子类EditView允许用户进行编辑。


以下为TextView常用的属性以及对应方法进行说明,最后在附上一个简易Demo。

常用属性:


以上就是关于TextView 的属性、有兴趣的朋友自行写一个Demo体验下。


这里先看下显示效果:


主Activity.java如下:


package com.dsl.ui_application_03;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    TextView text1;
    TextView text2;
    TextView text3;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initUI();
    }

    /**
     * 控件初始化
     */
    public void initUI()
    {
        text1 = (TextView)findViewById(R.id.text1);
        text2 = (TextView)findViewById(R.id.text2);
        text2 = (TextView)findViewById(R.id.text3);
        MyTextlistener my = new MyTextlistener();
        text1.setOnClickListener(my);
        text2.setOnClickListener(my);
        text3.setOnClickListener(my);
    }

    /**
     * 自定义监听类,该类实现了View类
     */
    class MyTextlistener implements View.OnClickListener{

        @Override
        public void onClick(View v) {
            switch (v.getId())
            {
                case R.id.text1://改变第一行字体显示
                    text1.setText("第一行!");
                break;
                case R.id.text2://改变第二行字体显示
                    text1.setText("第二行!");
                    break;
                case R.id.text3://改变第三行字体显示
                    text1.setText("第三行!");
                    break;
            }
        }
    }

}

主.xml文件如下:


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.dsl.ui_application_03.MainActivity">

    <TextView
        android:id="@+id/text1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!" />
    <TextView
        android:id="@+id/text2"
        android:layout_marginTop="30dp"
        android:layout_below="@id/text1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@color/colorAccent"
        android:textSize="20dp"
        android:text="你们好!我是单胜凌!" />
    <TextView
        android:id="@+id/text3"
        android:layout_marginTop="30dp"
        android:layout_below="@id/text2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@color/colorPrimary"
        android:textSize="50dp"
        android:text="Hello Android!" />
</RelativeLayout>


该控件讲解到此结束!!!

源工程地址如下:

https://github.com/DSLAndroid/UI_Application_03



本资源来自单胜凌!!!

Android靠自学!!!

祝各位IT人士早日取得成功!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值