/*******************************************************************************
* Copyright (c) 2012 Manning
* See the file license.txt for copying permission.
******************************************************************************/
package com.manning.androidhacks.hack010;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Html;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.method.LinkMovementMethod;
import android.text.style.BackgroundColorSpan;
import android.text.style.ForegroundColorSpan;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView textView1 = (TextView) findViewById(R.id.my_text_view_html);
textView1.setText(Html.fromHtml(getString(R.string.text1)));
textView1.setMovementMethod(LinkMovementMethod.getInstance());
//新建Spannable对象,用于文本处理
Spannable text2 = new SpannableString(getString(R.string.text2));
//将1到3个字符设为红色背景
text2.setSpan(new BackgroundColorSpan(Color.RED), 1, 4, 0);
//将5到8个字符设为红色背景,空格也算字符
text2.setSpan(new ForegroundColorSpan(Color.BLUE), 5, 9, 0);
((TextView) findViewById(R.id.my_text_view_spannable)).setText(text2);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
textview文本格式设置
共31个文件
class:8个
png:6个
xml:4个
需积分: 16 20 下载量 198 浏览量
2014-10-31
18:10:15
上传
评论
收藏 52KB RAR 举报
温馨提示
默认状态下,同一个TextView显示的文本格式一致,运用Html.fromHtml( )方法或者SpannableString类可以设定不同的显示格式。参考: 编辑文章 - 博客频道 - CSDN.NET http://write.blog.csdn.net/postedit/40657573
资源推荐
资源详情
资源评论
收起资源包目录
hack010.rar (31个子文件)
hack010
.project 810B
project.properties 361B
proguard.cfg 1KB
src
com
manning
androidhacks
hack010
MainActivity.java 1KB
AndroidManifest.xml 808B
res
drawable-ldpi
icon.png 2KB
drawable-hdpi
icon.png 4KB
drawable-mdpi
icon.png 3KB
layout
main.xml 802B
drawable-xhdpi
values
strings.xml 352B
.settings
org.eclipse.jdt.core.prefs 177B
assets
gen
com
manning
androidhacks
hack010
BuildConfig.java 174B
R.java 879B
.classpath 475B
bin
resources.ap_ 11KB
classes
com
manning
androidhacks
hack010
R$layout.class 436B
BuildConfig.class 373B
R$drawable.class 442B
R$attr.class 382B
R$id.class 483B
R.class 629B
R$string.class 498B
MainActivity.class 1KB
AndroidManifest.xml 808B
dexedLibs
annotations-c1eb6cc2405a1deed10a8a1b61004884.jar 943B
jarlist.cache 120B
res
crunch
drawable-ldpi
icon.png 2KB
drawable-hdpi
icon.png 4KB
drawable-mdpi
icon.png 2KB
classes.dex 5KB
hack010.apk 15KB
共 31 条
- 1
资源评论
阿呀波
- 粉丝: 18
- 资源: 24
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功