解決TextView行尾小方格問題
Android中,有時用TextView打開UTF-8文本文件,在每行的末尾會出現一個小方格,這主要是由于換行符"r"造成的。
解決方法很簡單,用空格代替"r"即可,即string = string.replace("\r", ""),代碼段如下:
baos是ByteArrayOutputStream類,用來讀文本文件的。
1
CharSequence tempStr;
2
tempStr = new String(baos.toString().replace("\r", ""));
3
TextView m_TextView = new TextView(this);
4
m_TextView.setBackgroundColor(Color.BLACK);
5
m_TextView.setText(tempStr);

2

3

4

5

posted on 2010-02-19 13:25 江天部落格 閱讀(480) 評論(0) 編輯 收藏 所屬分類: Android