有點不夠smart的方式, 用一筆一筆TextView setTypeface(typeface, style);
typeface 的參數 |
.Typeface.DEFAULT |
.Typeface.DEFAULT_BOLD |
.Typeface.MONOSPACE |
.Typeface.SANS_SERIF |
.Typeface.SERIF |
style 的參數 |
.Typeface.NORMAL |
.Typeface.BOLD |
.Typeface.BOLD_ITALIC |
.Typeface.ITALIC |
package com.tsots.Typeface;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.graphics.Color;
import android.graphics.Typeface;
public class DefaultTypeface extends Activity
{
TextView tv_d;
TextView tv_d_bold;
TextView tv_d_bold_italic;
TextView tv_d_italic;
TextView tv_db;
TextView tv_db_bold;
TextView tv_db_bold_italic;
TextView tv_db_italic;
TextView tv_m;
TextView tv_m_bold;
TextView tv_m_bold_italic;
TextView tv_m_italic;
TextView tv_ss;
TextView tv_ss_bold;
TextView tv_ss_bold_italic;
TextView tv_ss_italic;
TextView tv_s;
TextView tv_s_bold;
TextView tv_s_bold_italic;
TextView tv_s_italic;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv_d = (TextView) findViewById (R.id.tv_d);
tv_d_bold = (TextView) findViewById (R.id.tv_d_bold);
tv_d_bold_italic = (TextView) findViewById (R.id.tv_d_bold_italic);
tv_d_italic = (TextView) findViewById (R.id.tv_d_italic);
tv_db = (TextView) findViewById (R.id.tv_db);
tv_db_bold = (TextView) findViewById (R.id.tv_db_bold);
tv_db_bold_italic = (TextView) findViewById (R.id.tv_db_bold_italic);
tv_db_italic = (TextView) findViewById (R.id.tv_db_italic);
tv_m = (TextView) findViewById (R.id.tv_m);
tv_m_bold = (TextView) findViewById (R.id.tv_m_bold);
tv_m_bold_italic = (TextView) findViewById (R.id.tv_m_bold_italic);
tv_m_italic = (TextView) findViewById (R.id.tv_m_italic);
tv_ss = (TextView) findViewById (R.id.tv_ss);
tv_ss_bold = (TextView) findViewById (R.id.tv_ss_bold);
tv_ss_bold_italic = (TextView) findViewById (R.id.tv_ss_bold_italic);
tv_ss_italic = (TextView) findViewById (R.id.tv_ss_italic);
tv_s = (TextView) findViewById (R.id.tv_s);
tv_s_bold = (TextView) findViewById (R.id.tv_s_bold);
tv_s_bold_italic = (TextView) findViewById (R.id.tv_s_bold_italic);
tv_s_italic = (TextView) findViewById (R.id.tv_s_italic);
tv_d.setTypeface(Typeface.DEFAULT, Typeface.NORMAL);
tv_d.setBackgroundColor(Color.YELLOW);
tv_d_bold.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
tv_d_bold_italic.setTypeface(Typeface.DEFAULT, Typeface.BOLD_ITALIC);
tv_d_italic.setTypeface(Typeface.DEFAULT, Typeface.ITALIC);
tv_db.setTypeface(Typeface.DEFAULT_BOLD, Typeface.NORMAL);
tv_db.setBackgroundColor(Color.YELLOW);
tv_db_bold.setTypeface(Typeface.DEFAULT_BOLD, Typeface.BOLD);
tv_db_bold_italic.setTypeface(Typeface.DEFAULT_BOLD, Typeface.BOLD_ITALIC);
tv_db_italic.setTypeface(Typeface.DEFAULT_BOLD, Typeface.ITALIC);
tv_m.setTypeface(Typeface.MONOSPACE, Typeface.NORMAL);
tv_m.setBackgroundColor(Color.YELLOW);
tv_m_bold.setTypeface(Typeface.MONOSPACE, Typeface.BOLD);
tv_m_bold_italic.setTypeface(Typeface.MONOSPACE, Typeface.BOLD_ITALIC);
tv_m_italic.setTypeface(Typeface.MONOSPACE, Typeface.ITALIC);
tv_ss.setTypeface(Typeface.SANS_SERIF, Typeface.NORMAL);
tv_ss.setBackgroundColor(Color.YELLOW);
tv_ss_bold.setTypeface(Typeface.SANS_SERIF, Typeface.BOLD);
tv_ss_bold_italic.setTypeface(Typeface.SANS_SERIF, Typeface.BOLD_ITALIC);
tv_ss_italic.setTypeface(Typeface.SANS_SERIF, Typeface.ITALIC);
tv_s.setTypeface(Typeface.SERIF, Typeface.NORMAL);
tv_s.setBackgroundColor(Color.YELLOW);
tv_s_bold.setTypeface(Typeface.SERIF, Typeface.BOLD);
tv_s_bold_italic.setTypeface(Typeface.SERIF, Typeface.BOLD_ITALIC);
tv_s_italic.setTypeface(Typeface.SERIF, Typeface.ITALIC);
}
}
沒有留言:
張貼留言