2011-06-24 3 views
5

私はそのアプリケーションでAndroid 2.2で1つのアプリケーションを作成しています AndroidアプリケーションのTextViewにヒンディー語のテキストを表示したいとします。Androidアプリケーションでフォントを追加する方法

+0

[Android appicaに外部フォントを追加する方法(http://stackoverflow.com/questions/5634245/how-to-add-external-fonts-to-android-application) –

答えて

17

プロジェクト内の資産フォルダにフォントを追加します。..

が私を助けてください(どのようにテキストビューで「मैंछात्रहूँ」単語を追加するために)、以下

TextView hindiTextView=(TextView)findViewById(R.id.txtbx); 
Typeface hindiFont=Typeface.createFromAsset(getAssets(),"fonts/fontname.ttf"); 
mytextView.setTypeface(hindiFont); 

はそのホープスニペットを使用役に立ったレイアウトファイルの

+0

ありがとうその作品... –

+0

それは動作していない、矩形のボックスだけを表示、私はvigyapti.ttfファイル –

+0

にフォントフォルダーのエラーを表示しました。フォントフォルダーをインクルードするようにしました。リソースフォルダー内に含まれています。 – Giridharan

3

1)フォントの内部に "資産" フォルダ及びペーストフォントの内部に "フォント" フォルダを追加

2フォルダ):

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:orientation="vertical" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
     > 

    <TextView 
      android:id="@+id/custom_font" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="मैं छात्र हूँ" 
      /> 

3)活性の場合テキストを設定するには、以下のコードを使用してください:

TextView txt = (TextView) findViewById(R.id.custom_font); 
Typeface font = Typeface.createFromAsset(getAssets(), "hindifont.ttf"); 
txt.setTypeface(font); 
関連する問題