日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

Android textview字体颜色显示和图片显示

發布時間:2024/1/23 Android 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android textview字体颜色显示和图片显示 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1,可以在布局文件中設置

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>
2,在代碼中顯示html代碼
1editText2.setText(Html.fromHtml(? "<font color=#E61A6B>紅色代碼</font> "+ "<i><font color=#1111EE>藍色斜體代碼</font></i>"+"<u><i><font color=#1111EE>藍色斜體加粗體下劃線代碼</font></i></u>"));

效果圖


01package rw.textView;
02??
03import android.R.integer;
04import android.app.Activity;
05import android.app.SearchManager.OnCancelListener;
06import android.graphics.drawable.Drawable;
07import android.os.Bundle;
08import android.text.Html;
09import android.text.Html.ImageGetter;
10import android.text.Spannable;
11import android.text.SpannableString;
12import android.text.style.ImageSpan;
13import android.view.View;
14import android.view.View.OnClickListener;
15import android.widget.EditText;
16import android.widget.ImageButton;
17??
18public class TextViewTestActivity extends Activity {
19????/** Called when the activity is first created. */
20????private EditText editText,editText2,editText3;
21????private ImageButton imageButton01,imageButton02,imageButton03;
22????@Override
23????public void onCreate(Bundle savedInstanceState) {
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(? "<font color=#E61A6B>紅色代碼</font> "+ "<i><font color=#1111EE>藍色斜體代碼</font></i>"+"<u><i><font color=#1111EE>藍色斜體加粗體下劃線代碼</font></i></u>"));
33???????// editText3.setText(Html.fromHtml("<img src='"+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(View v) {
42????????????????// TODO Auto-generated method stub
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 dra)
59????????{
60????????????Drawable drawable=getResources().getDrawable(dra);
61????????????drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
62????????????SpannableString spannableString = new SpannableString("pics");
63????????????ImageSpan imageSpan=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字体颜色显示和图片显示的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。