1

目前我正在使用字符串在警报对话框中显示文本,有没有办法直接使用资产 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();
}
4

1 回答 1

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);
        }
于 2014-11-22T13:12:01.827 回答