This is my textView
InputStream is = getAssets().open(readFromFile);
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
String line = reader.readLine();
arabicFont =Typeface.createFromAsset(getAssets(),"hactyp.ttf");
tv.setTypeface(arabicFont);
SpannableStringBuilder ssb = new SpannableStringBuilder(message);
ssb.setSpan(new UnderlineSpan(),0,message.length(),0);
tv.setText(ssb);
tv.setMovementMethod(new ScrollingMovementMethod());
while(line != null) {
if(message.equals(line)) {
while(!("end".equals(line))) {
line = reader.readLine();
tv.setText(tv.getText() +" \n" + line);
}
}
line = reader.readLine();
}
tv.setTextSize(24);
is.close();
}
Formatting done by span is getting overlayed by tv.setText(tv.getText() +" \\n" + line); Since there is a singleText view. Also since i am reading from a text file line by line, and appending to textView till i recieve a token, is their any better way to apply spanning in this scenario ?
You can't pass the SpannableStringBuilder
directly to tv.setText();
You have to return the String from the buffer using toString()
like this:
tv.setText(ssb.toString());
You also have to use toString()
when calling getText()
on a TextView. So you would call that like this:
tv.getText().toString()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.