您的位置:首页 > 产品设计 > UI/UE

Android UI控件之TextView

2016-12-02 15:25 337 查看
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人士早日取得成功!!!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: