TextView和EditText中添加图片(ImageSpan)
编辑框中加图片,以前一直以为很复杂,后来发现android有些类已经很好的实现了这些功能.
代码如下:
- mSubjectDetailView = (TextView) findViewById(R.id.subject_detail);
- CharSequence text = "如图所示★,dsfdsfdddd,如果fdsfs★东东";
- SpannableStringBuilder builder = new SpannableStringBuilder(text);
- String rexgString = "★";
- Pattern pattern = Pattern.compile(rexgString);
- Matcher matcher = pattern.matcher(text);
- while (matcher.find()) {
- builder.setSpan(
- new ImageSpan(this, R.drawable.ic_launcher), matcher.start(), matcher
- .end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
- }
- mSubjectDetailView.setText(builder);
布局:
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- tools:context=".MainActivity" >
- <TextView
- android:id="@+id/my_title"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_centerHorizontal="true"
- android:layout_centerVertical="true"
- android:text="@string/hello_world" />
- <TextView
- android:id="@+id/subject_detail"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:minHeight="50dp"
- android:gravity="center_vertical"
- android:text="subject"
- android:textColor="@android:color/primary_text_light_nodisable"
- android:background="@android:color/white"
- android:textSize="25sp" />
- </RelativeLayout>
效果:

TextView和EditText中添加图片(ImageSpan)的更多相关文章
- Android EditText中插入图片并响应点击事件
EditText中插入图片基本就是两种方法: ,通过Html.fromHtml(..)来实现 [mw_shl_code=java,true]eText.append(Html.fromHtml(&qu ...
- 在RichTextBox控件中添加图片和文字
public void SetText(RichTextBox rtb) { rtb.Text = "在RichTextBox控件中添加图片和文字" + Environment.N ...
- ArcMap图层属性表中添加图片
一看标题是不是有点懵?懵就对了!刚接触到的时候我也有点懵,属性表不是都是文本啊数字啊之类的格式,怎么还可以存图片,下面就带大家来看看吧! 一.关于图层入库问题 图层进入数据库和图层以shp格式存储时, ...
- 关于在Silverlight中添加图片的问题
在Silverlight中添加图片,目前支持的Image格式有jpg和png两种,如何在目录中添加,有些什么技巧呢? <StackPanel Background="White&quo ...
- 如何在github的README.md中添加图片
如何在github的README.md中添加图片 总结: 链接引用: 简介: 1.在github上的仓库建立一个存放图片的文件夹,文件夹名字随意.如:img ...
- ag-grid 表格中添加图片
ag-grid是一种非常好用的表格,网上搜索会有各种各样的基本用法,不过对于在ag-grid 表格中添加图片我没有找到方法,看了官方的文档,当然英文的自己也是靠网页翻译,最后发现有这么一个例子,我知道 ...
- iview+vue 表格中添加图片
开门见山,话不多说,要在表格中添加图片,可以使用td: <table " width="100%"> <tr class="tr-style ...
- 在EditText中添加QQ表情
本文参考自:http://blog.csdn.net/wulianghuan/article/details/8583921 在输入框中输入表情是每个聊天软件的必备功能,做到这点仅需要将表情放入工程图 ...
- TextView和EditText中的setFilters方法说明
在TextView中有一个方法public void setFilters(InputFilter[] filters),API中有一句说明:Sets the list of input filter ...
随机推荐
- SpringMVC实战(三种控制器方式)
1.前言 上篇博客着重说了一下SpringMVC中几种处理映射的方式,这篇博客来说一下SpringMVC中几种经常使用的控制器. 2.经常使用控制器 2.1 ParameterizableViewC ...
- Maven基础教程 分类: C_OHTERS 2015-04-10 22:53 232人阅读 评论(0) 收藏
更多内容请参考官方文档:http://maven.apache.org/guides/index.html 官方文档很详细,基本上可以查找到一切相关的内容. 另外,快速入门可参考视频:孔浩的maven ...
- js进阶 12-7 pageY和screenY以及clientY的区别是什么
js进阶 12-7 pageY和screenY以及clientY的区别是什么 一.总结 一句话总结:pageY是距文件,screenY是获取显示器屏幕位置的坐标,clientY是页面视口. 没有滚动条 ...
- [array] leetCode-1-Two Sum-Easy
leetCode-1-Two Sum-Easy descrition Given an array of integers, return indices of the two numbers suc ...
- [Docker] Build a Simple Node.js Web Server with Docker
Learn how to build a simple Node.js web server with Docker. In this lesson, we'll create a Dockerfil ...
- perl对比两个文件的行
perl对比两个文件的行 对比两个文件的各行,得到A与B相同的行/A与B不相同的行 主要功能 得到相同行 得到A中包含,B不包含的行 得到B中包含,A中不包含的行 具体执行情况 Perl代码 #!/u ...
- Struts(22)标签库具体解释
要使用Struts2的标签,仅仅须要在JSP页面加入例如以下一行定义就可以: <%@ taglib prefix="s" uri="/struts-tags&quo ...
- Linux 常用性能工具
Linux 常用性能工具简介. 一.wget 文件下载 使用wget下载单个文件:wget URL 下载并以不同的文件名保存:wget -O wordpress.zip URL wget限速下载:wg ...
- 阿里云Java镜像:基本配置和总体说明
本文中的内容,来自阿里云镜像系统自带的说明. 下次不想用镜像了,感觉也没有节省多少工作量. 一.软件 1.nginx /usr/local/nginx 2.tomcat-7 /var/tomcat/ ...
- css 弹性盒模型Flex 布局
参考文章:http://www.runoob.com/w3cnote/flex-grammar.html Flex 布局是什么:采用Flex布局的元素,称为Flex容器(flex container) ...