简体   繁体   English

我们可以在“警报”对话框中使用资产html文件吗?

[英]Can we use asset html files in Alert dialog?

Currently i am using string to show text in alert dialog , is there a way to use assets html file directly without using layout and show alert dialog like this code 目前,我正在使用字符串在警报对话框中显示文本,有没有一种方法可以直接使用资产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();
}

try this way, 尝试这种方式

 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);
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM