我使用此代码向用户索取语言:
void AskForLanguage() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Choose a language");
final String[] arrsLanguages;
arrsLanguages = new String[6];
arrsLanguages[0] = "English";
arrsLanguages[1] = "Español (Spanish)";
arrsLanguages[2] = "Français (French)";
arrsLanguages[3] = "Pусский язык (Russian)";
arrsLanguages[4] = "العربية (Arabic)";
arrsLanguages[5] = "简体中文 (Simplified Chinese)";
builder.setSingleChoiceItems(arrsLanguages, -1, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int iPosition) {
//Do some work
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
}
适用于英语,西班牙语和法语等文本,但对话框显示“?”俄语,阿拉伯语或中文的符号。有什么想法吗?
答案 0 :(得分:1)
我使用strings.xml文件解决了:
<string name="RussianInRussian">"Pусский язык (Russian)"</string>
<string name="ChineseInChinese">"简体中文 (Simplified Chinese)"</string>
然后
arrsLanguages[3] = getString(R.string.RussianInRussian);
arrsLanguages[5] = getString(R.string.ChineseInChinese);
答案 1 :(得分:0)
试试这个
arrsLanguages[5] = URLDecoder.decode("简体中文 (Simplified Chinese)", "utf-8");
有时您的设备可能不支持Español
字体,因此请尝试下载一些Español
ttf (字体)并设置它们以检查其是否显示