我正在开发一个应用程序,我想在其中为用户提供三种语言选项,如英语、印地语和旁遮普语(区域语言)。
我想知道最好的方法是什么? 我找到的一种方法是制作英语、印地语的三个不同的 xml 文件和旁遮普语。然后解析这些xml文件。我已经知道我们如何在 android 中显示旁遮普字体。但是我必须在我的应用程序中使用 4-5 本书。所以那种方式看起来不合适。
我还必须在我的应用程序中添加书签功能。那么谁能建议我使用三种语言的不同书籍的最佳方式,从那里添加书签功能也很容易。
感谢任何帮助。
最佳答案
将每个版本存储为原始资源(在/res/raw 中)。把它拿出来
public static String getRawFile(int resourceId, Resources resources) {
Writer writer;
try {
InputStream is = resources.openRawResource(resourceId);
writer = new StringWriter();
char[] buffer = new char[BUFFER_SIZE];
try {
Reader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
int n;
while ((n = reader.read(buffer)) != -1) {
writer.write(buffer, 0, n);
}
} finally {
is.close();
}
} catch (Exception ex) {
Log.e(TAG, "Unable to read raw resource!", ex);
return null;
}
return writer.toString();
}
这样调用:
Resources resources = context.getResources();
String text = Utilities.getRawFile(R.raw.test_response, resources));
关于android - 选择在 android 中查看不同语言的文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11498680/