2017-09-14 13 views
-2

アンドロイドEditTextでペルシャ語で電話番号を入力します。テキストを編集するためにFarsiフォントを設定しましたが、機能しませんでした。私は多くを検索しましたが、それらのすべては、EditTextで入力していないTextviewの静的テキストにset Farsiフォントについて話しました。どうすればこれを達成できますか? おかげは、ペルシャ語の数字をアンドロイドの編集テキストに入力できません。

答えて

2

これを試してみてください:

public class CustomFontEditText extends EditText { 


private Context context; 
private AttributeSet attrs; 
private int defStyle; 

public CustomFontEditText(Context context) { 
    super(context); 
    this.context=context; 
    init(); 
} 

public CustomFontEditText(Context context, AttributeSet attrs) { 
     super(context, attrs); 
     this.context=context; 
     this.attrs=attrs; 
     init(); 
} 

public CustomFontEditText(Context context, AttributeSet attrs, int defStyle) { 
     super(context, attrs, defStyle); 
     this.context=context; 
     this.attrs=attrs; 
     this.defStyle=defStyle; 
     init(); 
} 

private void init() { 
     Typeface font=Typeface.createFromAsset(getContext().getAssets(), "fonts/myfont.ttf"); 
     this.setTypeface(font); 
} 
@Override 
public void setTypeface(Typeface tf, int style) { 
    tf=Typeface.createFromAsset(getContext().getAssets(), "fonts/farsi.ttf"); 
    super.setTypeface(tf, style); 
} 

@Override 
public void setTypeface(Typeface tf) { 
    tf=Typeface.createFromAsset(getContext().getAssets(), "fonts/farsi.ttf"); 
    super.setTypeface(tf); 
} 

注:

あなたのフォント名とfarsi.ttfを交換し、あなたのXMLではなくデフォルトEditTextCustomFontEditTextを使用

関連する問題