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 ...
随机推荐
- 【习题5-3 UVA-10935】Throwing cards away I
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 用STL的queue写 [代码] #include <bits/stdc++.h> using namespace st ...
- 【47.76%】【Round #380B】Spotlights
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- Virtualizing physical memory in a virtual machine system
A processor including a virtualization system of the processor with a memory virtualization support ...
- GCD下载后清除缓存
//GCD下载后清除缓存1 —(void)didReceiveMemoryWarning{ [super didReceiveMemoryWarning]; //清除缓存 [self.cache re ...
- swift开发网络篇 - post 请求
/** 所有网络请求,统一使用异步请求! 在今后的开发中,如果使用简单的get/head请求,可以用NSURLConnction异步方法 GET查/POST增/PUT改/DELETE删/HEAD GE ...
- 【42.86%】【Codeforces Round #380D】Sea Battle
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- [TypeStyle] Use fallback values in TypeStyle for better browser support
You can increase the browser support of your CSS using fallback values and vendor prefixes. This les ...
- 程序猿学英语——In September the English learning summary
转眼间9月份又过去了,又该好好总结一下这个月的英语学习情况了. 在暑假快结束的时候.9期师姐给我们測了英语快照.当初測的时候就发现一个问题:当測自己听过尤其是读过的东 西的时候,自己都能听出来.測自己 ...
- linux下实现监控进程网络带宽
嗯,近期都在网易游戏实习,所以貌似有段时间没有上来写点东西了... 来网易游戏实习最基本的目的事实上就是想知道在游戏公司里面工作都是些什么内容,毕竟自己曾经也没有接触过游戏公司.. 还比較的好奇.. ...
- Jedis 源代码阅读一 —— Jedis
这是jedis 源代码文件夹,我们接下来选择性阅读重要的接口以及实现. └─redis └─clients ├─jedis │ │ BinaryClient.java │ │ BinaryJedis. ...