can';在android编辑文本中键入波斯语数字

can';在android编辑文本中键入波斯语数字,android,fonts,android-edittext,Android,Fonts,Android Edittext,我想在android EditText中用波斯语键入电话号码。我将波斯语字体设置为编辑文本,但不起作用。我也搜索了很多,但都讨论了在Textview中将波斯语字体设置为静态文本而不是在EditText中键入。我怎样才能做到这一点? 谢谢试试这个: public class CustomFontEditText extends EditText { private Context context; private AttributeSet attrs; private int defStyle

我想在android EditText中用波斯语键入电话号码。我将波斯语字体设置为编辑文本,但不起作用。我也搜索了很多,但都讨论了在Textview中将波斯语字体设置为静态文本而不是在EditText中键入。我怎样才能做到这一点? 谢谢

试试这个:

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中使用
CustomFontEditText
而不是默认的
EditText
,尝试以下操作:

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中使用
CustomFontEditText
而不是默认的
EditText