Android textview字体颜色显示和图片显示
2012-10-12 12:57
393 查看
1,可以在布局文件中设置
2,在代码中显示html代码
效果图
1 | < EditText |
2 | android:id = "@+id/editText1" |
3 | android:textColor = "#2BD54D" |
4 | android:layout_width = "match_parent" |
5 | android:layout_height = "wrap_content" > |
6 | </ EditText > |
1 | editText2.setText(Html.fromHtml( "<fontcolor=#E61A6B>红色代码</font>" + "<i><fontcolor=#1111EE>蓝色斜体代码</font></i>" + "<u><i><fontcolor=#1111EE>蓝色斜体加粗体下划线代码</font></i></u>" )); |
01 | package rw.textView; |
02 |
03 | import
|
04 | import
|
05 | import
|
06 | import
|
07 | import
|
08 | import
|
09 | import
|
10 | import
|
11 | import
|
12 | import
|
13 | import
|
14 | import
|
15 | import
|
16 | import
|
17 |
18 | public class TextViewTestActivity extends Activity{ |
19 | /**Calledwhentheactivityisfirstcreated.*/ |
20 | private EditTexteditText,editText2,editText3; |
21 | private ImageButtonimageButton01,imageButton02,imageButton03; |
22 | @Override |
23 | public void onCreate(BundlesavedInstanceState){ |
24 | super .onCreate(savedInstanceState); |
25 | setContentView(R.layout.main); |
26 | editText=(EditText)findViewById(R.id.editText1); |
27 | editText2=(EditText)findViewById(R.id.editText2); |
28 | editText3=(EditText)findViewById(R.id.editText3); |
29 | imageButton01=(ImageButton)findViewById(R.id.imageButton1); |
30 | imageButton02=(ImageButton)findViewById(R.id.imageButton2); |
31 | imageButton03=(ImageButton)findViewById(R.id.imageButton3); |
32 | editText2.setText(Html.fromHtml( "<fontcolor=#E61A6B>红色代码</font>" + "<i><fontcolor=#1111EE>蓝色斜体代码</font></i>" + "<u><i><fontcolor=#1111EE>蓝色斜体加粗体下划线代码</font></i></u>" )); |
33 | //editText3.setText(Html.fromHtml("<imgsrc='"+R.drawable.qq+"'/>",imageGetter,null)); |
34 | imageButton01.setOnClickListener( new MyListener()); |
35 | imageButton02.setOnClickListener( new MyListener()); |
36 | imageButton03.setOnClickListener( new MyListener()); |
37 | } |
38 | class MyListener implements OnClickListener{ |
39 |
40 | @Override |
41 | public void onClick(Viewv){ |
42 | //TODOAuto-generatedmethodstub |
43 | switch (v.getId()){ |
44 | case R.id.imageButton1: |
45 | SetImage(R.drawable.amazed); |
46 | break ; |
47 | case R.id.imageButton2: |
48 | SetImage(R.drawable.angry); |
49 | break ; |
50 | case R.id.imageButton3: |
51 | SetImage(R.drawable.isync); |
52 | break ; |
53 | default : |
54 | break ; |
55 | } |
56 | } |
57 | } |
58 | void SetImage( int
|
59 | { |
60 | Drawabledrawable=getResources().getDrawable(dra); |
61 | drawable.setBounds( 0 , 0 ,drawable.getIntrinsicWidth(),drawable.getIntrinsicHeight()); |
62 | SpannableStringspannableString= new SpannableString( "pics" ); |
63 | ImageSpanimageSpan= new ImageSpan(drawable,ImageSpan.ALIGN_BASELINE); |
64 | spannableString.setSpan(imageSpan, 0 ,spannableString.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); |
65 | editText3.setText(spannableString); |
66 | } |
67 | } |
相关文章推荐
- Android textview字体颜色显示和图片显示
- Android textview字体颜色显示和图片显示
- Android textview字体颜色显示和图片显示
- android中TextView分段显示不同颜色,字体,时间
- android在TextView中设置超链接,字体大小,字体颜色,图片
- Android TextView使用HTML处理字体样式、显示图片等
- textview中显示不同颜色的字体与显示图片
- Android中让TextView的字体部分显示颜色
- Android的TextView/EditText使用CharacterStyle&SpannableString来处理图片显示、字体样式、超链接等
- Android的TextView使用Html来处理图片显示、字体样式、超链接等
- 【工作笔记】android TextView、EditText对部分内容设置颜色、字体、超链接、图片
- android中TextView分段显示不同颜色,字体,时间
- Android的TextView/EditText使用CharacterStyle&SpannableString来处理图片显示、字体样式、超链接等
- Android TextView 字体颜色分段显示
- Android的TextView使用Html来处理图片显示、字体样式、超链接等
- Android的TextView使用Html来处理图片显示、字体样式、超链接等
- Android TextView使用HTML处理字体样式、显示图片等
- Android的TextView/EditText使用CharacterStyle&SpannableString来处理图片显示、字体样式、超链接等
- Android TextView使用HTML处理字体样式、显示图片等
- Android TextView使用HTML处理字体样式、显示图片等