android - Spannable 을 잘 사용하면 TextView 의 마스터!! |
참조 : http://flavienlaurent.com/blog/2014/01/31/spans/
BulletSpan
/*
public BulletSpan (int gapWidth, int color)
-gapWidth: gap in px between bullet and text
-color: bullet color (optionnal, default is transparent)
*/
//create a black BulletSpan with a gap of 15px
span = new BulletSpan(15, Color.BLACK);
QuoteSpan
/*
public QuoteSpan (int color)
-color: quote vertical line color (optionnal, default is Color.BLUE)
*/
//create a red quote
span = new QuoteSpan(Color.RED);
AlignmentSpan.Standard
/*
public Standard(Layout.Alignment align)
-align: alignment to set
*/
//align center a paragraph
span = new AlignmentSpan.Standard(Layout.Alignment.ALIGN_CENTER);
UnderlineSpan
//underline a character
span = new UnderlineSpan();
StrikethroughSpan
//strikethrough a character
span = new StrikethroughSpan();
SubscriptSpan
//subscript a character
span = new SubscriptSpan();
SuperscriptSpan
//superscript a character
span = new SuperscriptSpan();
BackgroundColorSpan
/*
public BackgroundColorSpan (int color)
-color: background color
*/
//set a green background
span = new BackgroundColorSpan(Color.GREEN);
ForegroundColorSpan
/*
public ForegroundColorSpan (int color)
-color: foreground color
*/
//set a red foreground
span = new ForegroundColorSpan(Color.RED);
ImageSpan
//replace a character by pic1_small image
span = new ImageSpan(this, R.drawable.pic1_small);
StyleSpan
/*
public StyleSpan (int style)
-style: int describing the style (android.graphics.Typeface)
*/
//set a bold+italic style
span = new StyleSpan(Typeface.BOLD | Typeface.ITALIC);
TypefaceSpan
/*
public TypefaceSpan (String family)
-family: a font family
*/
//set the serif family
span = new TypefaceSpan("serif");
TextApperanceSpan
/*
public TextAppearanceSpan(Context context, int appearance, int colorList)
-context: a valid context
-appearance: text appearance resource (ex: android.R.style.TextAppearance_Small)
-colorList: a text color resource (ex: android.R.styleable.Theme_textColorPrimary)
public TextAppearanceSpan(String family, int style, int size, ColorStateList color, ColorStateList linkColor)
-family: a font family
-style: int describing the style (android.graphics.Typeface)
-size: text size
-color: a text color
-linkColor: a link text color
*/
//set the serif family
span = new TextAppearanceSpan(this/*a context*/, R.style.SpecialTextAppearance);
<style name="SpecialTextAppearance" parent="@android:style/TextAppearance">
<item name="android:textColor">@color/color1</item>
<item name="android:textColorHighlight">@color/color2</item>
<item name="android:textColorHint">@color/color3</item>
<item name="android:textColorLink">@color/color4</item>
<item name="android:textSize">28sp</item>
<item name="android:textStyle">italic</item>
</style>
AbsoluteSizeSpan
/*
public AbsoluteSizeSpan(int size, boolean dip)
-size: a size
-dip: false, size is in px; true, size is in dip (optionnal, default false)
*/
//set text size to 24dp
span = new AbsoluteSizeSpan(24, true);
RelativeSizeSpan
/*
public RelativeSizeSpan(float proportion)
-proportion: a proportion of the actual text size
*/
//set text size 2 times bigger
span = new RelativeSizeSpan(2.0f);
ScaleXSpan
/*
public ScaleXSpan(float proportion)
-proportion: a proportion of actual text scale x
*/
//scale x 3 times bigger
span = new ScaleXSpan(3.0f);
MaskFilterSpan
/*
public MaskFilterSpan(MaskFilter filter)
-filter: a filter to apply
*/
//Blur a character
span = new MaskFilterSpan(new BlurMaskFilter(density*2, BlurMaskFilter.Blur.NORMAL));
//Emboss a character
span = new MaskFilterSpan(new EmbossMaskFilter(new float[] { 1, 1, 1 }, 0.4f, 6, 3.5f));
'프로그래밍 놀이터 > 안드로이드, Java' 카테고리의 다른 글
Admob 의 standalone sdk 가 deprecated 된다? (0) | 2014.04.28 |
---|---|
[android] textAllCaps 속성. (0) | 2014.04.28 |
[Tutorial] AndEngine Introduction (0) | 2014.04.24 |
[android] Fragment State 제대로 관리하기. (0) | 2014.04.24 |
keytool and openssl command for debug.keystore hash print nothing - which is for kakao developer or facebook sdk (0) | 2014.04.22 |
댓글