页面类
类名称:MainActivity
package com.example.android_fonts_test;
import android.support.v7.app.ActionBarActivity;import android.content.Context;import android.graphics.Typeface;import android.os.Bundle;import android.view.Menu;import android.view.MenuItem;import android.widget.TextView;
public class MainActivity extends ActionBarActivity {
private Context mContext; private TextView test_font_1; private TextView test_font_2; private TextView test_font_3; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mContext = this; // 字体 Typeface typeface_1 = Typeface.createFromAsset(mContext.getAssets(),"fonts/Beyond Wonderland.ttf"); test_font_1 = (TextView)findViewById(R.id.test_font_1); test_font_1.setTypeface(typeface_1); Typeface typeface_2 = Typeface.createFromAsset(mContext.getAssets(),"fonts/Channel.ttf"); test_font_2 = (TextView)findViewById(R.id.test_font_2); test_font_2.setTypeface(typeface_2); Typeface typeface_3 = Typeface.createFromAsset(mContext.getAssets(),"fonts/JFHolNte.ttf"); test_font_3 = (TextView)findViewById(R.id.test_font_3); test_font_3.setTypeface(typeface_3); }
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; }
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); }}