Android在TextView中实现RichText风格
2016-06-25 16:25
399 查看
参考:
Android实战技巧:用TextView实现Rich Text---在同一个TextView中设置不同的字体风格
Demo:private SpannableStringBuilder content = new SpannableStringBuilder(); private static final ForegroundColorSpan STYLE_ERROR = new ForegroundColorSpan(Color.RED); private static final ForegroundColorSpan STYLE_INFO = new ForegroundColorSpan(Color.BLACK); private int start = 0; private int end = 0; public void appendLog(String msg,int type){ TextView logView = (TextView)findViewById(R.id.logView); content.append(msg); start = end; end += msg.length(); switch (type){ case Log.TYPE_ERROR: content.setSpan(STYLE_ERROR,start,end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); break; case Log.TYPE_INFO: content.setSpan(STYLE_INFO,start,end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); break; default: break; } if(logView!=null){ logView.setText(content); //scroll to the end int offset = logView.getLineCount() * logView.getLineHeight(); if(offset > logView.getHeight()){ logView.scrollTo(0,offset - logView.getHeight()); } } }
相关文章推荐
- android设置背景色为透明
- 打好Android基础,实战中运用基础
- Android Studio 获取 sha1、MD5签名
- 实现Android的MVP框架
- RecyclerView之使用ItemTouchHelper和ItemTouchHelper.Callback实现条目拖拽排序
- 4.0、Android Studio配置你的构建
- 4.0、Android Studio配置你的构建
- Android 绘制N阶Bezier曲线
- Android GridView 的使用
- Android的Fragment中onActivityResult不被调用的最终解决方案
- Android传感器完全解析
- android 通知(1)
- Android中获取手机通信录中的联系人
- unable to start the daemon process (安卓项目不能运行报错)
- Android中的数据存储(一)----- 文件存储
- Android4编程入门经典 - 学习摘录笔记 - 1
- android json解析
- android 四大组件之Service(7) 结合通知
- Ubuntu编译vlc-android
- Android深度系列—Activity四种启动方式与栈原理