Android font effects: stroke and relief effects

Source: Internet
Author: User

 

Package CN. iimob;

Import Android. App. activity;
Import Android. Graphics. embossmaskfilter;
Import Android. Graphics. typeface;
Import Android. Graphics. Paint. style;
Import Android. OS. Bundle;
Import Android. Text. textpaint;
Import Android. widget. textview;

Public class demo extends activity {
/** Called when the activity is first created .*/
Private textview;
Private textview textview1;
Private textview textview2;
@ Override
Public void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Setcontentview (R. layout. Main );
Textview = (textview) findviewbyid (R. Id. Title );
// Font
Textview. settypeface (typeface. createfromasset (this. getassets (), "zy.3gp "));
Textview. settext ("earth on Mars ");
Textpaint TP1 = textview. getpaint ();
Tp1.setstrokewidth (3 );
Tp1.setstyle (style. fill_and_stroke );
Tp1.setfakeboldtext (true );

Textview1 = (textview) findviewbyid (R. Id. title1 );
// Font
Textview1.settypeface (typeface. createfromasset (this. getassets (), "zy.3gp "));
Textview1.settext ("earth on Mars ");

Textview2 = (textview) findviewbyid (R. Id. title2 );
Textview2.settext ("earth on Mars ");

Textpaint TP2 = textview2.getpaint ();
// Font
Textview2.settypeface (typeface. createfromasset (this. getassets (), "zy.3gp "));
Tp2.setfakeboldtext (true );
// Set the direction of the light source
Float [] direction = new float [] {1, 1, 1 };
// Set the ambient brightness
Float light = 0.4f;
// Select the reflection level to be applied
Float specular = 6;
// Apply a certain level of blur to the mask
Float blur = 3.5f;
Embossmaskfilter maskfilter = new embossmaskfilter (Direction, light, specular, blur );
Tp2.setmaskfilter (maskfilter );
}
}

 

 

Note: Assets \ zy.3gp is the font library.

 

 

Res \ values \ styles. xml

<? XML version = "1.0" encoding = "UTF-8"?>

<Resources>
<Style name = "audiofileinfooverlaytext0">
<Item name = "Android: paddingleft"> 4px </item>
<Item name = "Android: paddingbottom"> 4px </item>
<Item name = "Android: textcolor" >#000000 </item>
<Item name = "Android: textsize"> 60sp </item>
</Style>
<Style name = "audiofileinfooverlaytext1">
<Item name = "Android: paddingleft"> 4px </item>
<Item name = "Android: paddingbottom"> 4px </item>
<Item name = "Android: textcolor"> # ffffff </item>
<Item name = "Android: textsize"> 60sp </item>
</Style>
<Style name = "audiofileinfooverlaytext2">
<Item name = "Android: paddingleft"> 4px </item>
<Item name = "Android: paddingbottom"> 4px </item>
<Item name = "Android: textcolor"> # ffffff </item>
<Item name = "Android: textsize"> 60sp </item>
</Style>
</Resources>

 

Res \ Layout \ main. xml

<? XML version = "1.0" encoding = "UTF-8"?>

<Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: Orientation = "vertical" Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent" Android: Background = "# ffffff">

<Absolutelayout Android: Id = "@ + ID/absolutelayout01" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content">
<Textview style = "@ style/audiofileinfooverlaytext0" Android: Id = "@ + ID/Title" Android: text = "Hello word"
Android: layout_gravity = "bottom" Android: gravity = "center_vertical | center_horizontal"
Android: layout_width = "640px" Android: layout_height = "151px"> </textview>
<Textview style = "@ style/audiofileinfooverlaytext1" Android: Id = "@ + ID/title1" Android: text = "Hello word"
Android: layout_gravity = "bottom" Android: gravity = "center_vertical | center_horizontal"
Android: layout_width = "640px" Android: layout_height = "151px"> </textview>
</Absolutelayout>

<Textview style = "@ style/audiofileinfooverlaytext2" Android: Id = "@ + ID/title2" Android: text = "Hello word"
Android: layout_gravity = "bottom" Android: gravity = "center_vertical | center_horizontal"
Android: layout_width = "640px" Android: layout_height = "151px"> </textview>
</Linearlayout>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.