Far*_*hah 22
使用波斯语字体显示数字的另一种方法是使用以下助手类:
public class FormatHelper {
private static String[] persianNumbers = new String[]{ "?", "?", "?", "?", "?", "?", "?", "?", "?", "?" };
public static String toPersianNumber(String text) {
if (text.length() == 0) {
return "";
}
String out = "";
int length = text.length();
for (int i = 0; i < length; i++) {
char c = text.charAt(i);
if ('0' <= c && c <= '9') {
int number = Integer.parseInt(String.valueOf(c));
out += persianNumbers[number];
}
else if (c == '?') {
out += '?';
}
else {
out += c;
}
return out;
}
}
Run Code Online (Sandbox Code Playgroud)
将此类保存为UTF8格式并使用它,如下面的代码FormatHelper.toPersianNumber(numberString);
Far*_*hah 14
通过使用Typeface类,视图的字体类型可以更改为Farsi字体,因此数字可以通过Farsi字体显示:
Typeface typeface = Typeface.createFromAsset(getAssets(), "FarsiFontName.ttf");
myView.setTypeface(typeface);
Run Code Online (Sandbox Code Playgroud)
将区域设置设置为阿拉伯语、埃及
int i = 25;
NumberFormat nf = NumberFormat.getInstance(new Locale("ar","EG"));
nf.format(i);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6350 次 |
| 最近记录: |