Android常用控件一之文本控件

来源:互联网 发布:5g网络产业链 编辑:程序博客网 时间:2024/05/19 16:49

1、显示文本的控件(TextView)

android:text 设置文本框内文本内容

<TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"         android:text="我是文本控件的内容"        />

android:autoLink   是否将符合格式的文本转化为可单击的超链接形式

      取值范围:none (无)| web(网址)| phone(电话)| map(地址)| all(都可以,系统判断)

<TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="https://www.baidu.com/"        android:autoLink="web"        />
android:lines  默认占几行

<TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="1234567890234234234234234234242342423423423423423409"        android:lines="1"        />

android:minLines  最少占几行

<TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="12345678902342342342342342342423424234234234234234098765432434234234234"        android:minLines="2"        />

android:textColor  字体颜色

<TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="我是字体颜色控件"        android:textColor="@color/colorPrimary"        />

android:textSize  字体大小

<TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="我是字体大小控件"        android:textSize="15dp"        />
android:textStyle  字体风格 如粗体 斜体等

<TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="我是字体样式控件"        android:textStyle="bold"        />

android:background  设置背景 可以是颜色或图片

<TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="我是字体背景控件"        android:background="@color/colorPrimaryDark"        />

android:typeface 

1、字体

2、android系统默认支持三种字体

3、要使用其他字体,需要把字体文件(.tff)放在assets/fonts目录下,然后使用代码设置

4、代码:

4.1、Typeface typeFace=Typeface.createFromAsset(getAssets(),"fonts/FZSTK.TTF");

4.2、textView.setTypeface(typeFace);

android:ellipsize  文本超过TextView的长度是如何处理

    取值范围:none | start | middle | end | marquee

    如果取值为marquee 需要加上三个属性

1、android:focusable="true"

2、android:focusableInTouchMode="true"

3、android:clickable="true"

    marquee默认无限循环,可以通过android:marqueeRepeatLimt="1"设置循环次数

android:drawableXX 设置文本的icon,XX是任意的方向,在字体的哪个方向添加

<TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="我是字体icon控件"        android:drawableLeft="@drawable/icon_user"        />