2014-11-22 67 views
0

目前我使用的字符串,以显示警报对话框文本,有没有办法资产使用HTML文件的情况下直接使用的布局和显示警告对话框这样的代码我们可以在警报对话框中使用资产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

你可以使用,但为这个coustem dailog框与webview的webview加载HTML文件 – 2014-11-22 13:05:32

+0

对不起,但我看不到任何资产。我不知道你想从资产文件中使用内容。请准确。 – greenapps 2014-11-22 13:06:12

+0

@Naveen你怎么能给我看一个例子 – Cervo 2014-11-22 13:06:42

回答

0

尝试这种方式,

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

我只是显示来自字符串的文本,而没有使用任何文本视图或布局。在你的代码中,我看到了这个TextView tv =(TextView)findViewById(R.id.text); tv.setText(text);我不明白 – Cervo 2014-11-22 13:27:33

相关问题