【发布时间】:2017-09-03 21:43:43
【问题描述】:
我有一个使用文本文件来获取文本的应用程序。我可以通过从文件中读取并将其附加到 textview 来获取文本并将其放入 Textview 并且效果很好,但我想为文本添加格式。比如让标题加粗等等。
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);
}
}
【问题讨论】: