Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/219.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Android设备中获取当前支持的语言?_Android_Localization_Locale - Fatal编程技术网

如何在Android设备中获取当前支持的语言?

如何在Android设备中获取当前支持的语言?,android,localization,locale,Android,Localization,Locale,我们如何检查Android设备上的选定语言支持?或者如何在Android设备中获取当前支持的语言您可以使用deLocale获取默认语言 Locale.getDefault()为默认值,Locale.getAvailableCales()为可用语言。 ()我创建了一个方法来检查是否支持特定语言 public static boolean isLanSupported(Context context, String text) { final int WIDTH_PX =

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

您可以使用deLocale获取默认语言

Locale.getDefault()为默认值,Locale.getAvailableCales()为可用语言。
()

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

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

谢谢J-Jamet的回答,但它不适用于所有语言。例如,在Nexus device Locale.getAvailableLocales()或Resources.getSystem().getAssets()中,getLocales()仅返回“印地语”和“旁遮普语”作为支持语言。但是,在任何应用程序中选择“古吉拉特”语言时,该设备都可以正常工作​​旧版本的API不正式支持的。古吉拉特邦必须有字体集成为根目录才能工作。XDA Post:对此非常抱歉,但对于这种语言,您还有更多的工作要做。不确定这是如何工作的!如果“ગુજરાતી" 不受支持。
位图
将有一些垃圾值。它与
orig