TextView字体,行距,html格式,超链接,对大长度的设定
颜色,大小
<span style="font-size:18px;"> <!-- 设置字体的大小,推荐用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" /></span>
行间距
<span style="font-size:18px;"><!-- 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" /></span>
内部文字识别
<!-- android:autoLink="web" 可以指定多个属性,根据属性来识别出内部的文字 -->
<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="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格式,超链接,对大长度的设定的更多相关文章
- android textview字体加粗 Android studio最新水平居中和垂直居中
android textview字体加粗 Android studio最新水平居中和垂直居中 Android中字体加粗在xml文件中使用android:textStyle=”bold”但是不能将中文设 ...
- Android 设置TextView字体颜色
设置TextView字体的颜色其实很简单,尤其是直接在XML文件中,可以直接通过textColor属性指定颜色值,达到设置文本颜色的效果:那在代码中如何动态设置字体的颜色值呢? 接下来,介绍如何通过J ...
- TextView字体,行距,html格式,超链接,最大长度的设定
颜色,大小 <!-- 设置字体的大小,推荐用sp做单位:字体颜色以#开头 --> <TextView android:id="@+id/textView1" an ...
- 前端基础-html 字体标签,排版标签,超链接,图片标签
主要内容: 字体标签: h1~h6.<font>.<u>.<b>.<strong><em>.<sup>.<sub> ...
- TextView字体大小及颜色设置
TextView设置文字大小及颜色: 1.1)通过xml配置 <TextView android:layout_width="match_parent" a ...
- 安卓TextView完美展示html格式代码
对于TextView展示html格式代码,最简单的办法就是使用textview.setText(Html.fromHtml(html));,即便其中有img标签,我们依然可以使用ImageGetter ...
- Android为TV端助力:(转载)修改TextView字体样式
一.开篇 因为 Android 字体相关的内容还比较多的.有时候其实我们只需要调整一下属性就可以满足设计师的需求,或者是一个退后的方案(毕竟有发版的时间卡住了),有一些效果可以大概满足需求. 那么本文 ...
- android TextView字体设置最少占多少行. 及其 Java String 字符串操作 . .
① 字体设置: 修改代码 : GridViewActivity.java priceTv为 TextView priceTv.setMaxLines(3); //当多与7个字fu的时候 , 其余字 ...
- TextView中使用Linkify添加超链接
首先,在TextView所属xml配置文件中,直接添加android:autoLink特性即可,它支持一个或多个(用分割线)自定义的值:none.web.email.phone或all. 另外, ...
随机推荐
- 《MySQL技术内幕 InnoDB存储引擎 》学习笔记
第1章 MySQL体系结构和存储引擎 1.3 MySQL存储引擎 数据库和文件系统最大的区别在于:数据库是支持事务的 InnoDB存储引擎: MySQL5.5.8之后默认的存储引擎,主要面向OLTP ...
- django为url写测试用例
这个和为orm写测试用例类似. 但为了区分文件,还是建议在app目录下,用tests_orm.py,tests_url.py这类单独文件加以区分. urls.py如果如这样. from django. ...
- [转] HTML5之FileReader的使用
HTML5定义了FileReader作为文件API的重要成员用于读取文件,根据W3C的定义,FileReader接口提供了读取文件的方法和包含读取结果的事件模型. FileReader的使用方式非常简 ...
- weblogic在64位windows的设置
最近遇到一些问题,需要调整weblogic的内存用于做压力测试,weblogic默认的内存是远远不能满足当前测试需求.由于服务器是64位8G的内存,但是在服务器上安装的jdk和weblogic都是32 ...
- MapReduce原理1
Mapreduce是一个分布式运算程序的编程框架,是用户开发“基于hadoop的数据分析应用”的核心框架: Mapreduce核心功能是将用户编写的业务逻辑代码和自带默认组件整合成一个完整的分布式运算 ...
- Java—Math类和随机数类
一.Math类(主要封装算数运算的静态方法) 定义: Math是没有构造方法的. java语言中提供了一个执行数学基本运算的Math类,Math类包括常用的数学运算和一些数学函数.还提供了一些常用的常 ...
- 简单实现一个EventEmiter
在前端开发中,“发布-订阅”也是“观察者模式”是一种常用的设计模式:之前对设计模式没有过深的认识,直到前段时间在封装一个运用AngularJS封装table组件时,遇到一个难题,那就是AngularJ ...
- StringBuilder的实现与技巧ZZ
在上一篇进一步了解String 中,发现了string的不便之处,而string的替代解决方案就是StringBuilder的使用..它的使用也很简单System.Text.StringBuild ...
- BZOJ.4819.[SDOI2017]新生舞会(01分数规划 费用流SPFA)
BZOJ 洛谷 裸01分数规划.二分之后就是裸最大费用最大流了. 写的朴素SPFA费用流,洛谷跑的非常快啊,为什么有人还T成那样.. 当然用二分也很慢,用什么什么迭代会很快. [Update] 19. ...
- 如何用dat批处理文件关闭某端口对应程序-Windows自动化命令
如何用dat批处理文件关闭某端口对应程序? 网上找到的大部分都是手动操作,第一步先查出端口,第二步在根据上一步查到的端口手动去关闭进程.但我的需求不是这样的,我需要全自动处理.用于 dubbo 服务进 ...