android - 我们可以在警报对话框中使用 Assets html 文件吗?

标签 android android-alertdialog about-box

目前我正在使用字符串在警报对话框中显示文本,有没有一种方法可以直接使用 Assets 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 {
            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);
        }

关于android - 我们可以在警报对话框中使用 Assets html 文件吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27077682/

相关文章:

android - 如何去除 Material Button 中图标的色调?

java - 为什么再次打开应用程序时权限对话框会消失?

android - 如何减小应用程序 (.apk) 大小

android - 为警报对话框设置 Android Theme.Light

java - Android:如何在自定义 AlertDialog 中检索 Edittext.getText()?

android - 部署到设备时未加载 cordova 包

android - 如何将电子邮件链接添加到布局 xml,Android

macos - 关于“应用程序”框,是否已将代理(UIElement)设置为"is"?

java - 如何更改 Mac OS X 的 Java 程序中的 "About"窗口?

.net - “关于”对话框中包含哪些重要信息?