2012-01-16 26 views
2

私はアラビア語でアプリケーションを開発しました。そして、私はAndroidデバイスの荒野をサポートしたいと思います。私はデバイスがアラビア語でそれをロードするか、英語でロードするためにアラビア語をサポートしているかどうかを検出したいと思います。Android言語サポートの検出

答えて

1

のリストを取得します。

ユーザーのロケールに基づいて適切な言語リソースを表示する場合は、フレームワークで簡単に許可されます。あなたはthis d.android.comの記事に記載されているように適切なリソースフォルダにstring.xmlファイルを追加し、OSは適切なリソースフォルダを使用します。

0

使用getAvailableLocales()あなたはちょうどあなたが<context>.getResources().getConfiguration().localeを使用することができます構成されたロケール(がjava.util.Localeある)チェックに必要がある場合は利用可能な言語

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