编辑框中加图片,以前一直以为很复杂,后来发现android有些类已经很好的实现了这些功能.
代码如下:
-
mSubjectDetailView=(TextView)findViewById(R.id.subject_detail);
-
-
CharSequencetext="如图所示★,dsfdsfdddd,如果fdsfs★东东";
-
SpannableStringBuilderbuilder=newSpannableStringBuilder(text);
-
StringrexgString="★";
-
Patternpattern=Pattern.compile(rexgString);
-
Matchermatcher=pattern.matcher(text);
-
-
while(matcher.find()){
-
builder.setSpan(
-
newImageSpan(this,R.drawable.ic_launcher),matcher.start(),matcher
-
.end(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
-
}
-
-
mSubjectDetailView.setText(builder);
布局:
-
<RelativeLayoutxmlns: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>
效果:
分享到:
相关推荐
基本控件案例集锦,Button,TextView,EditText,Toast,RadioButton 基本控件案例集锦,Button,TextView,EditText,Toast,RadioButton 基本控件案例集锦,Button,TextView,EditText,Toast,RadioButton 基本...
WhatsappFormatter,textView和editText的简单格式设置选项与whatsapp提供的相同。.zip
textview搜索 edittext搜索 文本光标定位,文本快速定位,文本标记
本人封装的一个工具类,可对textview和EditText中的部分字体修改颜色和大小。希望对大家有所帮助! 有四个构造方法,可以改变字体大小和颜色或者默认TextView本身的颜色大小都可以!! 代码中都写又详细的注释!
在TextView中添加图片的三种方式总结 1.使用SpannableString+ImageSpan 2.android:drawableBottom... 3。扩展TextView 复写onDraw
1、从Activity的TextView中获取字符串设置到AlertDialog的TextView和EditText中 2、将AlertDialog的EditText中的值设置到Activity的TextView中 新手在自定义AlertDialog上的疑问笔者猜测主要有两个: 1、自定义的...
常用控件:TextView EditText Button 项目文件
见博客:http://blog.csdn.net/baidu_nod/article/details/38310729
一个利用RxJava在TextView和EditText上渲染的markdown解析器,支持大部分语法以及部分语法在EditText上实时预览(yydcdut)
Android TextView EditText 插入 图片 工具类 包装 ,已包装好工具类,直接调用
4、如果一切正常,那么你会在虚拟设备看到常用的控件(包括TextView, EditText,AutoCompleteTextView,MultiAutoCompleteTextView,Button,ImageButton,ToggleButton,CheckBox和RadioButton),根据中文提示操作。...
Android中使用TextView、EditText完成登录验证的代码清单.pdf 学习资料 复习资料 教学资源
Android中使用TextView、EditText完成的新闻详情浏览的代码清单.pdf 学习资料 复习资料 教学资源
Android中使用TextView、EditText完成登录验证练习题的任务说明.pdf 学习资料 复习资料 教学资源
Android中使用TextView、EditText完成的新闻详情浏览教学案例的要求说明.pdf 学习资料 复习资料 教学资源
EditText和Textview的部分文字响应
Easily switch between EditText and TextView seamlessly. Grab via Gradle :coffee: dependencies { implementation 'com.camerash:toggleedittextview:0.1.1' } Usage :computer: ToggleEditTextView In your ...
一个可以用代号处理控件的阴影效果,以及用代号在TextView、EditText、Button等控件设置selector.zip
查看文章:[Android教程]TextView显示Html类解析的网页和图片及自定义标签 3、在TextView四周显示图片 mTVText.setText("setCompoundDrawables"); Drawable d = getResources().getDrawable(R.drawable.ic_launcher)...
edittext 与textview 所有属性详解