본문 바로가기
프로그래밍 놀이터/안드로이드, Java

android - Spannable 을 잘 사용하면 TextView 의 마스터!!

by 돼지왕 왕돼지 2014. 4. 25.
반응형


 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);


android - Spannable 을 잘 사용하면 TextView 의 마스터!!




QuoteSpan


/*

public QuoteSpan (int color)

-color: quote vertical line color (optionnal, default is Color.BLUE)

*/


//create a red quote

span = new QuoteSpan(Color.RED);


android - Spannable 을 잘 사용하면 TextView 의 마스터!!




AlignmentSpan.Standard


/*

public Standard(Layout.Alignment align)

-align: alignment to set

*/


//align center a paragraph

span = new AlignmentSpan.Standard(Layout.Alignment.ALIGN_CENTER);


android - Spannable 을 잘 사용하면 TextView 의 마스터!!




UnderlineSpan


//underline a character

span = new UnderlineSpan();


android - Spannable 을 잘 사용하면 TextView 의 마스터!!







StrikethroughSpan


//strikethrough a character

span = new StrikethroughSpan();


android - Spannable 을 잘 사용하면 TextView 의 마스터!!




SubscriptSpan


//subscript a character

span = new SubscriptSpan();


android - Spannable 을 잘 사용하면 TextView 의 마스터!!




SuperscriptSpan


//superscript a character

span = new SuperscriptSpan();


android - Spannable 을 잘 사용하면 TextView 의 마스터!!




BackgroundColorSpan


/*

public BackgroundColorSpan (int color)

-color: background color

*/


//set a green background

span = new BackgroundColorSpan(Color.GREEN);


android - Spannable 을 잘 사용하면 TextView 의 마스터!!




ForegroundColorSpan


/*

public ForegroundColorSpan (int color)

-color: foreground color

*/


//set a red foreground

span = new ForegroundColorSpan(Color.RED);


android - Spannable 을 잘 사용하면 TextView 의 마스터!!







ImageSpan


//replace a character by pic1_small image

span = new ImageSpan(this, R.drawable.pic1_small);


android - Spannable 을 잘 사용하면 TextView 의 마스터!!




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);


android - Spannable 을 잘 사용하면 TextView 의 마스터!!




TypefaceSpan


/*

public TypefaceSpan (String family)

-family: a font family

*/


//set the serif family

span = new TypefaceSpan("serif");


android - Spannable 을 잘 사용하면 TextView 의 마스터!!




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>


android - Spannable 을 잘 사용하면 TextView 의 마스터!!




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);


android - Spannable 을 잘 사용하면 TextView 의 마스터!!




RelativeSizeSpan


/*

public RelativeSizeSpan(float proportion)

-proportion: a proportion of the actual text size

*/


//set text size 2 times bigger 

span = new RelativeSizeSpan(2.0f);


android - Spannable 을 잘 사용하면 TextView 의 마스터!!




ScaleXSpan


/*

public ScaleXSpan(float proportion)

-proportion: a proportion of actual text scale x

*/


//scale x 3 times bigger 

span = new ScaleXSpan(3.0f);


android - Spannable 을 잘 사용하면 TextView 의 마스터!!







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));


android - Spannable 을 잘 사용하면 TextView 의 마스터!!


android - Spannable 을 잘 사용하면 TextView 의 마스터!!






반응형

댓글