Android---13---SpannableString

來源:互聯網
上載者:User

標籤:spannablestring   android開發   android   

SpannableString的屬性:

1、BackgroundColorSpan 背景色 
 2、ClickableSpan 文本可點擊,有點擊事件
 3、ForegroundColorSpan 文本顏色(前景色彩)
 4、MaskFilterSpan 修飾效果,如模糊(BlurMaskFilter)、浮雕(EmbossMaskFilter)
 5、MetricAffectingSpan 父類,一般不用
 6、RasterizerSpan 光柵效果
 7、StrikethroughSpan 刪除線(中劃線)
 8、SuggestionSpan 相當於預留位置
 9、UnderlineSpan 底線
 10、AbsoluteSizeSpan 絕對大小(文本字型)
 11、DynamicDrawableSpan 設定圖片,基於文本基準或底部對齊。
 12、ImageSpan 圖片
 13、RelativeSizeSpan 相對大小(文本字型)
 14、ReplacementSpan 父類,一般不用
 15、ScaleXSpan 基於x軸縮放
 16、StyleSpan 字型樣式:粗體、斜體等
 17、SubscriptSpan 下標(數學公式會用到)
 18、SuperscriptSpan 上標(數學公式會用到)
 19、TextAppearanceSpan 文本外貌(包括字型、大小、樣式和顏色)
 20、TypefaceSpan 文本字型
 21、URLSpan 文本超連結



import android.app.Activity;import android.content.Intent;import android.graphics.Color;import android.os.Bundle;import android.text.SpannableString;import android.text.Spanned;import android.text.method.LinkMovementMethod;import android.text.style.BackgroundColorSpan;import android.text.style.ClickableSpan;import android.text.style.ForegroundColorSpan;import android.text.style.StrikethroughSpan;import android.text.style.StyleSpan;import android.text.style.TypefaceSpan;import android.text.style.URLSpan;import android.text.style.UnderlineSpan;import android.view.Menu;import android.view.MenuItem;import android.view.View;import android.widget.TextView;/* 1、BackgroundColorSpan 背景色  2、ClickableSpan 文本可點擊,有點擊事件 3、ForegroundColorSpan 文本顏色(前景色彩) 4、MaskFilterSpan 修飾效果,如模糊(BlurMaskFilter)、浮雕(EmbossMaskFilter) 5、MetricAffectingSpan 父類,一般不用 6、RasterizerSpan 光柵效果 7、StrikethroughSpan 刪除線(中劃線) 8、SuggestionSpan 相當於預留位置 9、UnderlineSpan 底線 10、AbsoluteSizeSpan 絕對大小(文本字型) 11、DynamicDrawableSpan 設定圖片,基於文本基準或底部對齊。 12、ImageSpan 圖片 13、RelativeSizeSpan 相對大小(文本字型) 14、ReplacementSpan 父類,一般不用 15、ScaleXSpan 基於x軸縮放 16、StyleSpan 字型樣式:粗體、斜體等 17、SubscriptSpan 下標(數學公式會用到) 18、SuperscriptSpan 上標(數學公式會用到) 19、TextAppearanceSpan 文本外貌(包括字型、大小、樣式和顏色) 20、TypefaceSpan 文本字型 21、URLSpan 文本超連結 */public class MainActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);TextView textView1, textView2, textView3;textView1 = (TextView) findViewById(R.id.textview1);textView2 = (TextView) findViewById(R.id.textview2);textView3 = (TextView) findViewById(R.id.textview3);String text1, text2, text3;SpannableString spannableString1, spannableString2, spannableString3;text1 = "背景顏色,字型顏色";text2 = "百度連結,字型樣式";text3 = "刪除線 ,底線 ,點擊事件";spannableString1 = new SpannableString(text1);spannableString2 = new SpannableString(text2);spannableString3 = new SpannableString(text3);spannableString1.setSpan(new BackgroundColorSpan(Color.YELLOW), 0, 5,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);spannableString1.setSpan(new ForegroundColorSpan(Color.RED), 5, 9,Spanned.SPAN_EXCLUSIVE_INCLUSIVE);spannableString2.setSpan(new URLSpan("http://www.baidu.com"), 0, 4,Spanned.SPAN_EXCLUSIVE_INCLUSIVE);spannableString2.setSpan(new StyleSpan(android.graphics.Typeface.BOLD_ITALIC), 5, 9,Spanned.SPAN_EXCLUSIVE_INCLUSIVE);spannableString3.setSpan(new StrikethroughSpan(), 0, 3,Spanned.SPAN_EXCLUSIVE_INCLUSIVE);spannableString3.setSpan(new UnderlineSpan(), 5, 8,Spanned.SPAN_EXCLUSIVE_INCLUSIVE);spannableString3.setSpan(new ClickableSpan() {@Overridepublic void onClick(View widget) {// TODO Auto-generated method stubIntent intent = new Intent (MainActivity.this,activity1.class);startActivity(intent);}}, 9, 14, Spanned.SPAN_EXCLUSIVE_INCLUSIVE);textView1.setText(spannableString1);textView2.setText(spannableString2);textView3.setText(spannableString3);textView1.setMovementMethod(LinkMovementMethod.getInstance());textView2.setMovementMethod(LinkMovementMethod.getInstance());textView3.setMovementMethod(LinkMovementMethod.getInstance());}}


Android---13---SpannableString

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.