ビューにペルシア語 (ペルシア語) の数字を表示したい。たとえば、日付を計算してジャラリ暦に変換しましたが、ペルシャ数字で表示するにはどうすればよいですか?
10819 次
13 に答える
14
Typeface クラスを使用すると、ビューのフォント タイプをペルシア語フォントに変更できるため、数字をペルシア語フォントで表示できます。
Typeface typeface = Typeface.createFromAsset(getAssets(), "FarsiFontName.ttf");
myView.setTypeface(typeface);
于 2015-07-28T10:00:56.163 に答える
3
カスタム ビューを作成し、その上にペルシア語フォントを追加すると、最後にそれを xml ビューで使用できます。ほとんどのペルシア語フォントは、文字マップに英語の数字が含まれていないため、問題なく使用できます。例えば :
public class TextViewStyle extends TextView {
public TextViewStyle(Context context) {
super(context);
init(context, null, 0);
}
public TextViewStyle(Context context, AttributeSet attrs) {
this(context, attrs, 0);
init(context, attrs, 0);
}
public TextViewStyle(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(context, attrs, defStyle);
}
private void init(Context context, AttributeSet attrs, int defStyle){
try {
TypedArray a = context.obtainStyledAttributes(attrs,R.styleable.TextViewStyle, defStyle, 0);
String str = a.getString(R.styleable.TextViewStyle_fonttype);
switch (Integer.parseInt(str)) {
case 0:
str = "fonts/byekan.ttf";
break;
case 1:
str = "fonts/bnazanin.ttf";
break;
case 2:
str = "fonts/btitr.ttf";
break;
case 3:
str = "fonts/mjbeirut.ttf";
break;
case 4:
str = "fonts/bnazanin_bold.ttf";
break;
default:
str = "fonts/bnazanin.ttf";
break;
}
setTypeface(FontManager.getInstance(getContext()).loadFont(str));
} catch (Exception e) {
e.printStackTrace();
}
}
}
attr.xml :
<declare-styleable name="TextViewStyle">
<attr name="selected_background" format="integer"/>
<attr name="fonttype">
<enum name="byekan" value="0"/>
<enum name="bnazanin" value="1"/>
<enum name="btitr" value="2"/>
<enum name="mjbeirut" value="3"/>
<enum name="bnazaninBold" value="4"/>
</attr>
</declare-styleable>
于 2015-07-22T10:24:28.123 に答える