颜色,大小

<!-- 设置字体的大小,推荐用sp做单位;字体颜色以#开头 -->
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world"
android:textColor="#0000ff"
android:textSize="16sp" />

行间距

<!-- android:lineSpacingExtra="8dp"  设定行距 -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="万众瞩目的北京奥运会吉祥物于北京时间11日20:18正式揭晓,奥运吉祥物福娃:
形象为鱼、熊猫、奥运圣火、藏羚羊、燕子,名字是贝贝、晶晶、欢欢、迎迎、妮妮,即北京欢迎你"
android:textColor="#0000ff"
android:lineSpacingExtra="8dp"
android:layout_marginTop="16dp"
android:textSize="16sp" />

内部特殊文字识别,识别电话、邮箱等

 <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:autoLink="web"
android:text="Google一下: http://www.google.com.hk" />

设置最多能显示多少文字

<!-- android:maxLength="7"   设置显示文字的最大的长度 -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:maxLength="7"
android:text="1234567890" />

设定文字样式

android:textStyle="bold" 表示文字是粗体

<!-- android:textStyle="italic" 设定字体样式 -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="你好,android"
android:textColor="#000000"
android:layout_marginTop="16dp"
android:textStyle="italic" />

用样式文件来设定字体

<!-- style="@style/text_style"   用独立的样式文件作为字体样式,直接用style属性即可 -->
<TextView
android:text="你好,android"
android:layout_marginTop="16dp"
style="@style/text_style" />

这里用到的style文件

<style name="text_style">
<item name="android:textSize">20sp</item>
<item name="android:textColor">#ff0000</item>
<item name="android:textStyle">italic|bold</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
</style>

设置文字与图片的位置

<!-- android:drawableLeft="@drawable/ic_launcher"  设定文字与图片的位置,上下左右都行 -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/ic_launcher"
android:layout_marginTop="16dp"
android:text="左边是图片"/>

文字过长时显示的效果

<!-- ellipsize="end" 设定文字过长时的显示效果 -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:singleLine="true"
android:ellipsize="end"
android:text="设置当文字过长时,该控件该如何显示。可设置如下属性值:start省略号显示在开头;
    end省略号显示在结尾;
middle省略号显示在中间;
    marquee以跑马灯的方式显示(动画横向移动)"/>

通过代码进行文字的设定

package com.kale.textview;  

import android.app.Activity;
import android.graphics.Typeface;
import android.os.Bundle;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.widget.TextView; public class MainActivity extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); TextView tv = (TextView)findViewById(R.id.textView1); tv.getPaint().setFakeBoldText(true);//设置文字为粗体 Typeface typeFace =Typeface.createFromAsset(getAssets(),"fonts/mini.ttf");//加载自定义字体
tv.setTypeface(typeFace); String html_marquee =
"万众瞩目的北京奥运会<a href = 'http://www.baidu.com'>吉祥物</a>" + //超链接“吉祥物”字段到百度
"于北京时间11日20:18正式揭晓," +
"奥运吉祥物福娃:形象为鱼、熊猫、奥运圣火、藏羚羊、燕子," +
"名字是贝贝、晶晶、欢欢、迎迎、妮妮,即北京欢迎你 电话:15667856218";
CharSequence charSequence_marquee = Html.fromHtml(html_marquee);
tv.setText(charSequence_marquee);//设定textView显示的文字
tv.setMovementMethod(LinkMovementMethod.getInstance()); //点击时产生超链接效果,补写的话点击无效
} }

源码下载:http://download.csdn.net/detail/shark0017/7583515

TextView字体,行距,html格式,超链接,最大长度的设定的更多相关文章

  1. android textview字体加粗 Android studio最新水平居中和垂直居中

    android textview字体加粗 Android studio最新水平居中和垂直居中 Android中字体加粗在xml文件中使用android:textStyle=”bold”但是不能将中文设 ...

  2. Android 设置TextView字体颜色

    设置TextView字体的颜色其实很简单,尤其是直接在XML文件中,可以直接通过textColor属性指定颜色值,达到设置文本颜色的效果:那在代码中如何动态设置字体的颜色值呢? 接下来,介绍如何通过J ...

  3. TextView字体,行距,html格式,超链接,对大长度的设定

    颜色,大小 <span style="font-size:18px;"> <!-- 设置字体的大小,推荐用sp做单位:字体颜色以#开头 --> <Te ...

  4. [转帖]自动调整TextView字体大小以适应文字长度

    package com.test.android.textview; import android.content.Context; import android.graphics.Paint; im ...

  5. 前端基础-html 字体标签,排版标签,超链接,图片标签

    主要内容: 字体标签: h1~h6.<font>.<u>.<b>.<strong><em>.<sup>.<sub> ...

  6. TextView字体大小及颜色设置

    TextView设置文字大小及颜色: 1.1)通过xml配置 <TextView      android:layout_width="match_parent"     a ...

  7. 安卓TextView完美展示html格式代码

    对于TextView展示html格式代码,最简单的办法就是使用textview.setText(Html.fromHtml(html));,即便其中有img标签,我们依然可以使用ImageGetter ...

  8. Android为TV端助力:(转载)修改TextView字体样式

    一.开篇 因为 Android 字体相关的内容还比较多的.有时候其实我们只需要调整一下属性就可以满足设计师的需求,或者是一个退后的方案(毕竟有发版的时间卡住了),有一些效果可以大概满足需求. 那么本文 ...

  9. android TextView字体设置最少占多少行. 及其 Java String 字符串操作 . .

    ①  字体设置: 修改代码 :  GridViewActivity.java priceTv为 TextView priceTv.setMaxLines(3); //当多与7个字fu的时候 , 其余字 ...

随机推荐

  1. VisualSVN Server搭建SVN服务器<转>

    使用 VisualSVN Server来搭建本地的代码管理库是非常方便的.svn的那些“检查修改”.“代码版本自由回滚”.“版本日志”等等很多比较牛逼的功能. 在开发当中可谓是理想的开发助手.而且人脑 ...

  2. 【BZOJ】2289: 【POJ Challenge】圆,圆,圆

    题解 二分一个横坐标,过这个横坐标做一条和y轴平行的直线,相当于在这条直线上做区间覆盖,如果区间有交的话,那么答案是True 否则的话取两个不相交的区间,如果这两个圆相离或相切则不合法 否则看看相交的 ...

  3. sed匹配多行替换

    sed -i '/aaa/{:a;n;s/123/xyz/g;/eee/!ba}' yourfile 如题:aaa123123123123123eee怎么匹配aaa~eee(开始结束字符串确定),然后 ...

  4. Element-ui el-cascader不触发prop?

    html代码: <el-form label-position="right" label-width="100px" :model="form ...

  5. 004.Zabbix3.x-Server服务端安装

    一 环境基础 1.1 部署基础环境 部署Zabbix需要LAMP或LANP环境,数据库可以为MySQL或者MariaDB.硬件及存储条件按需配置. 1.2 常见依赖列表 Web前端需要支持的软件环境如 ...

  6. 3种纯css方法控制元素隐藏显示

    1.通过hover,也是最常用的方式.此方法要求按钮与被控制元素必须有层级关系.(兼容低端浏览器常用) <div class="nav-btn"> <h2> ...

  7. MySQL CPU %sys 高的案例分析(三)

    [现象] 最近有台服务器晚上CPU告警,系统抓取的故障期间的snapshot显示CPU %sys较高,同时context switch在300K以上. 是否过高的context switch引起的%s ...

  8. codeforces_1092c

    title: codeforces_1092c date: 2018-12-24 19:42:23 tags: acm 刷题 概述 一道有关字符串前缀后缀的题,,,自己迟早要坑在这字符串的题上,,,一 ...

  9. MyBatis 从浅入深 随笔整理

    MyBatis? archetypeCatalog = internal 本文档单独出现的_parameter都标识为变量名 一.三个基本要素: 核心接口和类 MyBatis 核心配置文件 SQL映射 ...

  10. Tecnomatix Process Designer & Process Simulate用法

    1. 删除项目 在AdminConsole->Project Action中,点击Delete project即可.