Android 2.x devanagari unicode issue

2019-05-26 02:57发布

I am trying to support for devanagari font for android 2.x (even though android 2.x is not capable of rendering the devanagari font) using following code. The code is working fine except having some issues with 'raswa' and 'dirga'. Is it possible to obtain the correct devanagari representation in android 2.x ?

Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/mangal.ttf");
TextView txtviewword=(TextView) findViewById(R.id.textViewWord);
txtviewword.setTypeface(typeface);

This is incorrect representation(from android 2.3):

enter image description here

This should have been rather like this(from android 4.4):

enter image description here

1条回答
何必那么认真
2楼-- · 2019-05-26 03:36

After analysing my situation over the problem, I found that swapping the position of 'raswa' with the alphabet ('akshar') itself would solve the problem for gingerbread. So, I swapped the position of 'raswa' and alphabet. So, this provided the problem workaround.

if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
   char[] array = content[1].toCharArray();   /*content[1] is a string containing the original version */
   for(int i=0; i<array.length; i++){
        char c = array[i];
        int code = (int) c;
        if (code == 2367){    //2367 is int value for 'raswa'
            char temp = array[i-1];
            array[i-1]=c;
            array[i]=temp;
        }
    }
    String str = String.copyValueOf(array); /*This string contains the swapped version(symantically its wrong, though. It's works as my solution.)*/
    Log.d("DetailActivity", "from gingerbread");
    Log.d("DetailActivity", str);
    if(!content[1].equals(null))txtviewdevanagari.setText(str);
}else{
    Log.d("DetailActivity", "from ICS+");
    if(!content[1].equals(null))txtviewdevanagari.setText(content[1]);
}
查看更多
登录 后发表回答