目前我正在使用字符串在警告对话框中显示文本,有没有办法直接使用资源html文件而不使用布局和显示警告对话框,如此代码
private void About() {
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle(getString(R.string.about));
alertDialog.setMessage(getString(R.stringabout));
alertDialog.setIcon(R.drawable.ic_launcher);
alertDialog.setButton(DialogInterface.BUTTON_NEUTRAL,
getString(R.string.lbl_dialog_close),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
close
}
});
alertDialog.show();
}
答案 0 :(得分:1)
试试这个,
try {
InputStream is = getAssets().open("yourhtmlfile.txt");
// We guarantee that the available method returns the total
// size of the asset... of course, this does mean that a single
// asset can't be more than 2 gigs.
int size = is.available();
// Read the entire asset into a local byte buffer.
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
// Convert the buffer into a string.
String text = new String(buffer);
// Finally stick the string into the text view.
TextView tv = (TextView)findViewById(R.id.text);
tv.setText(text);
} catch (IOException e) {
// Should never happen!
throw new RuntimeException(e);
}