2013年5月15日水曜日

TextViewのフォントをメイリオに変更してみた


ブログのフォントをメイリオに変更した記事を書いたら「ANDROID メイリオ」で検索してくれた方がたくさんいたようなので、ANDROIDアプリのフォントをメイリオに変更する記事を書きます。

やり方


1.メイリオフォントを入手

どこかから meiryo.ttf、meiryob.ttf をダウンロード(ググれば出てくるはず)

2.メイリオフォントを配置

assetsフォルダにダウンロードした meiryo.ttf、meiryob.ttf をコピー

3.TextViewを用意



    
    
    
    
    



4.MainActivityを編集

import android.os.Bundle;
import android.app.Activity;
import android.graphics.Typeface;
import android.view.Menu;
import android.widget.TextView;

public class MainActivity extends Activity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);

        TextView meiryo = (TextView)findViewById(R.id.meiryo);
        meiryo.setTypeface(Typeface.createFromAsset(getAssets(), "meiryo.ttf"));
        
        TextView meiryob = (TextView)findViewById(R.id.meiryob);
        meiryob.setTypeface(Typeface.createFromAsset(getAssets(), "meiryob.ttf"));
 }

 @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;
 }

}

5.実行

うまくできました。

スポンサーリンク

Related Posts Plugin for WordPress, Blogger...