编辑框中加图片,以前一直以为很复杂,后来发现android有些类已经很好的实现了这些功能.

代码如下:

[java] view
plain
copy

  1. mSubjectDetailView = (TextView) findViewById(R.id.subject_detail);
  2. CharSequence text = "如图所示★,dsfdsfdddd,如果fdsfs★东东";
  3. SpannableStringBuilder builder = new SpannableStringBuilder(text);
  4. String rexgString = "★";
  5. Pattern pattern = Pattern.compile(rexgString);
  6. Matcher matcher = pattern.matcher(text);
  7. while (matcher.find()) {
  8. builder.setSpan(
  9. new ImageSpan(this, R.drawable.ic_launcher), matcher.start(), matcher
  10. .end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
  11. }
  12. mSubjectDetailView.setText(builder);

布局:

[html] view
plain
copy

  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. xmlns:tools="http://schemas.android.com/tools"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. tools:context=".MainActivity" >
  6. <TextView
  7. android:id="@+id/my_title"
  8. android:layout_width="wrap_content"
  9. android:layout_height="wrap_content"
  10. android:layout_centerHorizontal="true"
  11. android:layout_centerVertical="true"
  12. android:text="@string/hello_world" />
  13. <TextView
  14. android:id="@+id/subject_detail"
  15. android:layout_width="match_parent"
  16. android:layout_height="wrap_content"
  17. android:minHeight="50dp"
  18. android:gravity="center_vertical"
  19. android:text="subject"
  20. android:textColor="@android:color/primary_text_light_nodisable"
  21. android:background="@android:color/white"
  22. android:textSize="25sp" />
  23. </RelativeLayout>

效果:

TextView和EditText中添加图片(ImageSpan)的更多相关文章

  1. Android EditText中插入图片并响应点击事件

    EditText中插入图片基本就是两种方法: ,通过Html.fromHtml(..)来实现 [mw_shl_code=java,true]eText.append(Html.fromHtml(&qu ...

  2. 在RichTextBox控件中添加图片和文字

    public void SetText(RichTextBox rtb) { rtb.Text = "在RichTextBox控件中添加图片和文字" + Environment.N ...

  3. ArcMap图层属性表中添加图片

    一看标题是不是有点懵?懵就对了!刚接触到的时候我也有点懵,属性表不是都是文本啊数字啊之类的格式,怎么还可以存图片,下面就带大家来看看吧! 一.关于图层入库问题 图层进入数据库和图层以shp格式存储时, ...

  4. 关于在Silverlight中添加图片的问题

    在Silverlight中添加图片,目前支持的Image格式有jpg和png两种,如何在目录中添加,有些什么技巧呢? <StackPanel Background="White&quo ...

  5. 如何在github的README.md中添加图片

    如何在github的README.md中添加图片 总结: 链接引用:![Image text](图片的链接地址) 简介: 1.在github上的仓库建立一个存放图片的文件夹,文件夹名字随意.如:img ...

  6. ag-grid 表格中添加图片

    ag-grid是一种非常好用的表格,网上搜索会有各种各样的基本用法,不过对于在ag-grid 表格中添加图片我没有找到方法,看了官方的文档,当然英文的自己也是靠网页翻译,最后发现有这么一个例子,我知道 ...

  7. iview+vue 表格中添加图片

    开门见山,话不多说,要在表格中添加图片,可以使用td: <table " width="100%"> <tr class="tr-style ...

  8. 在EditText中添加QQ表情

    本文参考自:http://blog.csdn.net/wulianghuan/article/details/8583921 在输入框中输入表情是每个聊天软件的必备功能,做到这点仅需要将表情放入工程图 ...

  9. TextView和EditText中的setFilters方法说明

    在TextView中有一个方法public void setFilters(InputFilter[] filters),API中有一句说明:Sets the list of input filter ...

随机推荐

  1. 【习题5-3 UVA-10935】Throwing cards away I

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 用STL的queue写 [代码] #include <bits/stdc++.h> using namespace st ...

  2. 【47.76%】【Round #380B】Spotlights

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  3. Virtualizing physical memory in a virtual machine system

    A processor including a virtualization system of the processor with a memory virtualization support ...

  4. GCD下载后清除缓存

    //GCD下载后清除缓存1 —(void)didReceiveMemoryWarning{ [super didReceiveMemoryWarning]; //清除缓存 [self.cache re ...

  5. swift开发网络篇 - post 请求

    /** 所有网络请求,统一使用异步请求! 在今后的开发中,如果使用简单的get/head请求,可以用NSURLConnction异步方法 GET查/POST增/PUT改/DELETE删/HEAD GE ...

  6. 【42.86%】【Codeforces Round #380D】Sea Battle

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  7. [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 ...

  8. 程序猿学英语——In September the English learning summary

    转眼间9月份又过去了,又该好好总结一下这个月的英语学习情况了. 在暑假快结束的时候.9期师姐给我们測了英语快照.当初測的时候就发现一个问题:当測自己听过尤其是读过的东 西的时候,自己都能听出来.測自己 ...

  9. linux下实现监控进程网络带宽

    嗯,近期都在网易游戏实习,所以貌似有段时间没有上来写点东西了... 来网易游戏实习最基本的目的事实上就是想知道在游戏公司里面工作都是些什么内容,毕竟自己曾经也没有接触过游戏公司.. 还比較的好奇.. ...

  10. Jedis 源代码阅读一 —— Jedis

    这是jedis 源代码文件夹,我们接下来选择性阅读重要的接口以及实现. └─redis └─clients ├─jedis │ │ BinaryClient.java │ │ BinaryJedis. ...