gpt4 book ai didi

android - 如何获取 Android 设备当前支持的语言?

转载 作者:太空狗 更新时间:2023-10-29 15:59:01 26 4
gpt4 key购买 nike

我们如何检查 Android 设备上所选语言的支持情况?或如何在 Android 设备中获取当前支持的语言

最佳答案

我创建了一种方法来检查是否支持特定语言。

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")

关于android - 如何获取 Android 设备当前支持的语言?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45031615/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com