TextView字体,行距,html格式,超链接,最大长度的设定
颜色,大小
<!-- 设置字体的大小,推荐用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格式,超链接,最大长度的设定相关推荐
- yytextview多种格式_Android 一个TextView字体设置多种不同颜色
最近由于项目需求,需要根据用户姓名与欢迎语字体颜色区分开来! 以前刚开始的时候会考虑用多个TextView配合 可是!如果用户数量不止一位呢!? 在baidu搜了一些资料,发现有些使用到了自定义Vie ...
- (转载)Android花样Text,设置TextView的字体、颜色、超链接等
使用Spannable或Html.fromHtml设置字体.颜色.超链接等 Android花样Text设置神器之SpanableString
- android textview 字体颜色设置,Android textview 设置不同的字体大小和颜色
在实际应用中,需要将一个字符串已不同的颜色,字体显示出来.当然完全可以通过不同textview拼接出来.也可以通过一个textview来展示. 步骤如下: 1.定义不同style . 不妨如下定义2个 ...
- TextView的autoLink属性设置超链接问题
需求如下:用一个view展示"请点击https://mp.csdn.net进行查找"这句话,并点击链接地址时可以进行跳转. 最近接到类似的这种需求,网上查找资料学习到了TextVi ...
- 将数字字符串格式化为指定长度
将数字字符串格式化为指定长度的JavaScript函数 function formatNum(number,len){var strLength = len - number.length;//格式长 ...
- Android 设置TextView字体加粗
今天,简单讲讲Android里如何设置TextView字体加粗. 不废话了,用过多次,还是没记住.直接上代码. 1.布局文件中这样设置即可: XML/HTML代码 android:textStyle= ...
- Android动态改变TextView字体颜色
Android动态改变TextView字体颜色 分类: Android 2012-06-04 21:56 141人阅读 评论(0) 收藏 举报 androidcolorslayout 必须在在res/ ...
- word柱状图垂直轴数值设定_Excel图表中设置坐标轴的字体、图案格式、刻度格式和数字格式的方法...
Excel图表中设置坐标轴的字体.图案格式.刻度格式和数字格式的方法,听说excel的教程在抖音很火,很多白领小朋友都在争相学习,下面就跟小编一起学习一下Excel图表中设置坐标轴的字体.图案格式.刻 ...
- graphpad做折线图坐标轴数字_Excel图表中设置坐标轴的字体、图案格式、刻度格式和数字格式的方法...
在Excel图表中,坐标轴是一个重要的元素.用户可以根据需要对坐标轴的样式进行设置,以使图表更加美观醒目.同时,通过对坐标轴的刻度等进行设置,也能够使图表更加清晰直观.本文介绍Excel图表中设置坐标 ...
- android textview字体大小设置
在实际工作中,经常会遇到要在代码中设置textview字体的大小,例如自定义组件中,设置字体的大小:比起直接在xml里面设置字体大小,在代码里面设置字体稍微复杂一些,因为有时候你设置字体后,效果完全和 ...
最新文章
- devDependencies与dependencies (转载)
- python爬虫如何运行在web_Python Web爬网-使用爬虫进行测试
- 如何选择漏电保护器规格型号_施工现场三级电箱如何配置?图示详解,清晰明了!...
- Oracle内部错误:ORA-07445[kcflfi()+466] [INT_DIVIDE_BY_ZERO]一例
- STM32 DSP库的使用方法
- linux下gsoap的初次使用 (c)
- iOS事件机制,以及不同手势使用touchesBegan等表现形式
- UCOSII系统移植详解
- window7安装jdk报错this version of the jdk is already installed
- 根据日期算星座 mysql,Hive 通过日期计算星座实例
- 动环监控安装及调试过程,动环监控调试是什么
- 如何搭建IPv6测试你的APP
- B站硬核up主稚晖君:对于有志学习嵌入式开发的软件工程师,我有这些建议!...
- 去除word转pdf时的图片黑边
- 用layui+metinfo 实现分页获取频道观看日志
- 拓展半导体材料和零件领域 SK集团布局解读
- (阿里云)Linux部署SSM项目全过程
- 优化扩展live555支持MP2T(mpeg2ts)RTSP拉流附源代码
- 供应商质量工程师(SQE)是做什么的?
- 阿里专家梁笑:2018双十一下单成功率99.9%!供应链服务平台如何迎接大促 1