检测Android语言支持

时间:2012-01-16 19:52:53

标签: android

我用阿拉伯语开发了应用程序,我想支持一大堆Android设备。我想检测设备是否支持阿拉伯语以阿拉伯语加载它或以英语加载。

3 个答案:

答案 0 :(得分:1)

如果您只需检查已配置的区域设置,则可以使用<context>.getResources().getConfiguration().localejava.util.Locale}。

如果要根据用户的语言环境显示相应的语言资源,框架很容易允许这样做。您将string.xml文件添加到适当的资源文件夹中,如this d.android.com文章中所述,操作系统将使用相应的文件夹。

答案 1 :(得分:0)

使用getAvailableLocales()获取可用语言列表

答案 2 :(得分:0)

您可以使用此方法检查特定语言支持

if (isSupported(baseContext, "हिन्दी"))
    languageList.add("हिन्दी")

用阿拉伯语单词替换हिन्दी

public static boolean isSupported(Context context, String text) {
        int w = 200, h = 80;

        Resources resources = context.getResources();
        float scale = resources.getDisplayMetrics().density;
        Bitmap.Config conf = Bitmap.Config.ARGB_8888;
        Bitmap bitmap = Bitmap.createBitmap(w, h, conf); // this creates a MUTABLE bitmap
        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 center
        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;
}

Refer full

相关问题