Android 在TextView里设置HTM…
来源:互联网 发布:linux socket 编辑:程序博客网 时间:2024/06/03 20:26
Android 在TextView里设置HTML
However, the documentation does not stipulate what HTML tags aresupported, which makes this method a bit hit-or-miss. Moreimportantly, it means that you cannot rely on what it will supportfrom release to release.
I have filed an issue
引用块标签
属性:
Common --一般属性
cite --被引用内容的URI
定义换行
表示引用的URI
定义标签 dfn是defining instance的缩写
强调标签 em是emphasis的缩写
定义斜体文字
段落标签,里面可以加入文字,列表,表格等
定义小字体的文字
定义删除线样式的文字 不符合标准网页设计的理念,不赞成使用. strike是strikethrough的缩写
重点强调标签
下标标签 sub是subscript的缩写
上标标签 sup是superscript的缩写
定义monospaced字体的文字 不赞成使用. 此标签对中文没意义 tt是teletypeor monospaced text style的意思
定义带有下划线的文字 u是underlinedtext style的意思
一、在xml文件中使用android:textStyle=”bold”
二、但是不能将中文设置成粗体,将中文设置成粗体的方法是:
TextView tv =( TextView)findViewById( R. id . TextView01);
TextPaint tp =tv. getPaint ( );
tp. setFakeBoldText( true) ;
Selecting, Highlighting, or Styling Portions ofText
You can highlight or style the formatting of strings or substringsof text in a TextView object. There are two ways to dothis:
If you use a string resource, you can add some simple styling, suchas bold or italic using HTML notation. The currently supported tagsare: B (bold), I (italic), U (underline), TT (monospace), BIG,SMALL, SUP (superscript), SUB (subscript), and STRIKE(strikethrough). So, for example, in res/values/strings.xml youcould declare this:
id="@+id/styled_welcome_message">We are so glad tosee you.
To style text on the fly, or to add highlighting or more complexstyling, you must use the Spannable object as describednext.
To style text on the fly, you must make sure the TextView is usingSpannable storage for the text (this will always be true if theTextView is an EditText), retrieve its text with getText(), andcall setSpan(Object, int, int, int), passing in a new style classfrom the android.text.style package and the selectionrange.
The following code snippet demonstrates creating a string with ahighlighted section, italic section, and bold section, and addingit to an EditText object.
// Get our EditText object.
EditText vw = (EditText)findViewById(R.id.text);
// Set the EditText's text.
vw.setText("Italic, highlighted, bold.");
// If this were just a TextView, we could do:
// vw.setText("Italic, highlighted, bold.",TextView.BufferType.SPANNABLE);
// to force it to use Spannable storage so styles can beattached.
// Or we could specify that in the XML.
// Get the EditText's internal text storage
Spannable str = vw.getText();
// Create our span sections, and assign a format toeach.
str.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), 0, 7,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
str.setSpan(new BackgroundColorSpan(0xFFFFFF00), 8, 19,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
str.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 21,str.length() - 1,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
I sometimes have the case to arrange the image next to thecharacters.
We can do it by putting TextView and ImageView intoLayout.
But today I introduce the other way using onlyTextView.
The following sample code is how to show the image next totext.
(show four image(left, top, right, bottom oftext))
final TextView textView =(TextView)findViewById(R.id.diet_log_label);
final Drawable iconDrawable =getResources().getDrawable(R.drawable.icon);
textView.setCompoundDrawablesWithIntrinsicBounds(iconDrawable,iconDrawable, iconDrawable, iconDrawable);
// or
textView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.icon,R.drawable.icon, R.drawable.icon,R.drawable.icon);
To show only left image, write"setCompoundDrawablesWithIntrinsicBounds(iconDrawable, null, null,null)"
- Android 在TextView里设置HTM…
- android TextView: 超出…
- Android: 在 TextView 里使用删除线
- Android ViewPager 里有…
- Android TextView文字横向自…
- 【转】Android TextView中文…
- android textview文字换行排…
- 解决android textview自动换…
- Android TextView字体颜色跟…
- android 中TextView文本控件…
- android TextView控件的字符…
- android 一个textview里设置字体的样式
- Android Studio中Textview里字体颜色的的设置:
- Android在一个TextView里显示不同样式的字体
- Android在一个TextView里显示不同样式的字体
- android 设置dialog样…
- android xml TextView属性
- android在代码里设置margin
- 学习收藏: Flex之State状态的使用 …
- 最近在连接BoneCP连接池,BoneCP主…
- StageWebView AIR 移动…
- js 屏蔽Backspace 回退键
- 多个Activity之间切换原理介绍
- Android 在TextView里设置HTM…
- Android获取存储卡路径的方式
- win7下 装Tornado2.2 for ARM
- 将map的级别扩大到固定的级别
- Python进制转换(二进制、十进制和十六进制)
- ps for mac 破解版
- 备用
- CvMemStorage动态内存存储及操作函数
- "mymath.h"