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));
}
}
Typeface使用
最新推荐文章于 2022-09-07 13:33:38 发布