2012-01-16 167 views
2

我已经开发了阿拉伯语应用程序,并且我想支持Android设备的狂野响起。我想要检测设备是否支持阿拉伯文以阿拉伯文加载或以英文加载。检测Android语言支持

回答

1

如果你只需要检查配置的区域,那么你可以使用<context>.getResources().getConfiguration().locale(是java.util.Locale)的列表。

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

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