我们如何检查Android设备上的所选语言支持?或如何获取Android设备中当前支持的语言
答案 0 :(得分:5)
我创建了一种方法来检查是否支持特定语言。
public static boolean isLanSupported(Context context, String text) {
final int WIDTH_PX = 200;
final int HEIGHT_PX = 80;
int w = WIDTH_PX, h = HEIGHT_PX;
Resources resources = context.getResources();
float scale = resources.getDisplayMetrics().density;
Bitmap.Config conf = Bitmap.Config.ARGB_8888;
Bitmap bitmap = Bitmap.createBitmap(w, h, conf);
Bitmap orig = bitmap.copy(conf, false);
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(Color.rgb(0, 0, 0));
paint.setTextSize((int) (14 * scale));
// draw text to the Canvas
Rect bounds = new Rect();
paint.getTextBounds(text, 0, text.length(), bounds);
int x = (bitmap.getWidth() - bounds.width()) / 2;
int y = (bitmap.getHeight() + bounds.height()) / 2;
canvas.drawText(text, x, y, paint);
boolean res = !orig.sameAs(bitmap);
orig.recycle();
bitmap.recycle();
return res;
}
以下方式调用方法
isLanSupported(getActivity(),"ગુજરાતી")
isLanSupported(getActivity(),"हिंदी")
isLanSupported(getActivity(),"English")
答案 1 :(得分:2)
您可以使用de 区域设置 object
获取默认语言Locale.getDefault()表示默认值, Locale.getAvailableLocales()表示可用的语言。 (See this other post)