-2

我需要读取存储在 raw 文件夹中的文件中的阿拉伯语文本并将文本显示到 textview 中。当我尝试这样做时,我收到了一条奇怪的文字。

4

1 回答 1

0

首先,您需要使用外部字体并将其添加到 assest 文件夹中。

TextView txtView;
Typeface arabicFont;

txtView= (TextView)findViewById(R.id.arabicTextDisplayTextView);
arabicFont =Typeface.createFromAsset(getAssets(),"arabic_fonttf");
txtView.setTypeface(arabicFont);     
txtView.setTextSize(20);

InputStream is = getResources().openRawResource(R.raw.arabic_text); 
BufferedInputStream bis = new BufferedInputStream(is);
int myInt=0;

try{
    ByteArrayBuffer myByteArray = new ByteArrayBuffer(100); 
    while((myInt = bis.read())!=-1)
    {
        if(myInt == 10) break;
        myByteArray.append((byte)myInt);
    }

    String arabicLine = new String(myByteArray.toByteArray(), 0, myByteArray.length(), "UTF-8");
    txtView.setText(arabicLine);
于 2013-09-17T09:07:52.047 回答