0
我有一个使用文本文件获取文本的应用程序。我可以通过从文件中读取文本并将其附加到文本视图并将其放入Textview中,然后将其放入Textview中,并且工作得很好,但我想向文本中添加格式。像使标题粗体等等。如何将来自文本文件的文本格式设置为Android中的文本视图
private void openFile()
{
String tema = "Message";
TextView temas = (TextView) findViewById(R.id.tutorial);
temas.setText(title);
temas.setTextSize(25);
temas.setTextColor(ContextCompat.getColor(this, R.color.colorPrimaryDark));
try {
InputStream is = getAssets().open("tutorials/tutorial1.txt");
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
String text = new String(buffer);
TextView tv = (TextView) findViewById(R.id.text);
tv.setText(text);
tv.setTextSize(20);
tv.setTextColor(Color.parseColor("#000000"));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
是的,但不适用于文本文件 –