2014-11-22 23 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

相關問題