我下载了一个单词,意思是Android sqlite.db字典文件。通过获取SQL查询
enslishWord="plausible";
hindiMeaning="lR;kHkklh]diViw.kZ]";通过使用印地语字体在TextView中,我得到了正确的印地语含义。如果我尝试用System.out.println(hindiMeaning);打印,它会打印lR;kHkklh]diViw.kZ]
我对这个问题感到困惑,并在寻找解决办法。请查看评论部分的原始Android sqlite.db Github链接。
发布于 2021-07-28 08:28:11
添加这个类
public class typeface extends TypefaceSpan {
Typeface typeface;
public typeface(String family, Typeface typeface) {
super(family);
this.typeface = typeface;
}
@Override
public void updateDrawState(TextPaint ds) {
ds.setTypeface(typeface);
}
@Override
public void updateMeasureState(TextPaint ds) {
ds.setTypeface(typeface);
}
}`将此方法添加到活动中
public SpannableString spannableString(String string, String your_working_hindi_font_name , Context context) {
SpannableString span = new SpannableString(string);
span.setSpan(new typeface("", Typeface.createFromAsset(context.getAssets(),
"" + your_working_hindi_font_name + ".ttf")), 0, span.length(), span.SPAN_EXCLUSIVE_EXCLUSIVE);
return span;
}
public void spannableToast(SpannableString text, Context context) {
Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
}调用方法表示吐司
spannableToast(spannableString(normal, "hindi" , getContext()) , getContext());设置文本
phoneTv.setText( spannableString(normal, "hindi" , getContext()));发布于 2021-07-28 11:21:05
如果我试图用System.out.println(HindiMeaning)打印;它打印lR;kHkklh]diViw.kZ]。
您是否试图在控制台中打印非英语字符?
android.graphics.Typeface是一个特定于安卓的类,而System.out.println是一个特定于Java的函数。默认情况下,您不能期望Java控制台打印出非英语字符。
在Android中,默认编码可以在studio64.exe.vmoptions文件中设置为一个普通的VM参数。此文件位于Android安装的根文件夹中,并包含一组JVM参数。将-Dfile.encoding=UTF-8添加到UTF-8中设置编码.
或者,您可以通过设置更改该选项。
参考资料:IntelliJ IDEA incorrect encoding in console output

https://stackoverflow.com/questions/68555071
复制相似问题