Typeface使用

package com.google.android.typefaceTest; 

import android.widget.TextView; 
import android.os.Bundle; 
import android.view.ViewGroup; 
import android.app.Activity; 
import android.graphics.Color; 
import android.widget.LinearLayout; 
import android.graphics.Typeface; 

/*本教程版权为http://blog.csdn.net/wudifeng 博客主人所有,代码随意使用,如想转载请表明出处,这是对写教程人得起码尊重,谢谢:) 
*/ 
public class typefaceTest extends Activity { 
/* 
* 
* android.graphics.Typeface java.lang.Object  
* The Typeface class specifies the typeface and intrinsic style of a font. This is 
* used in the paint, along with optionally Paint settings like textSize, 
* textSkewX, textScaleX to specify how text appears when drawn (and measured). 
*/ 
final int WRAP_CONTENT = ViewGroup.LayoutParams.WRAP_CONTENT; 

public void onCreate(Bundle icicle) { 
super.onCreate(icicle); 

LinearLayout linearLayout = new LinearLayout(this); 
linearLayout.setOrientation(LinearLayout.VERTICAL); 
setContentView(linearLayout); 

TextView redTV = new TextView(this); 
redTV.setTextSize(24.0f);//Set the paint's text size. This value must be > 0 
redTV.setText("abcdefgh"); 
redTV.setTypeface(Typeface.SERIF);//The NORMAL style of the default sans serif typeface. 
redTV.setTextColor(Color.RED); 
linearLayout.addView(redTV, new LinearLayout.LayoutParams(WRAP_CONTENT, 
WRAP_CONTENT)); 

TextView greenTV = new TextView(this); 
greenTV.setTextSize(24.0f);//Set the paint's text size. This value must be > 0
greenTV.setText("abcdefgh"); 
greenTV.setTypeface(Typeface.create(Typeface.SERIF, Typeface.BOLD)); 
greenTV.setTextColor(Color.GREEN); 
linearLayout.addView(greenTV, new LinearLayout.LayoutParams( 
WRAP_CONTENT, WRAP_CONTENT)); 

TextView blueTV = new TextView(this); 
blueTV.setTextSize(24.0f);//Set the paint's text size. This value must be > 0
blueTV.setText("abcdefgh"); 
blueTV.setTypeface(Typeface.create(Typeface.SERIF, Typeface.BOLD_ITALIC)); 
blueTV.setTextColor(Color.BLUE); 
linearLayout.addView(blueTV, new LinearLayout.LayoutParams( 
WRAP_CONTENT, WRAP_CONTENT)); 

TextView grayTV = new TextView(this); 
grayTV.setTextSize(24.0f);//Set the paint's text size. This value must be > 0
grayTV.setText("abcdefgh"); 
grayTV.setTypeface(Typeface.create(Typeface.SERIF, Typeface.ITALIC)); 
grayTV.setTextColor(Color.GRAY); 
linearLayout.addView(grayTV, new LinearLayout.LayoutParams( 
WRAP_CONTENT, WRAP_CONTENT)); 

TextView blackTV = new TextView(this); 
blackTV.setTextSize(24.0f);//Set the paint's text size. This value must be > 0
blackTV.setText("abcdefgh"); 
blackTV.setTypeface(Typeface.create(Typeface.SERIF, Typeface.NORMAL)); 
blackTV.setTextColor(Color.BLACK); 
linearLayout.addView(blackTV, new LinearLayout.LayoutParams( 
WRAP_CONTENT, WRAP_CONTENT)); 

} 

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值