2012-05-21 24 views
0

大多數時間視圖顯示正確,但有時顯示爲空白。Android:某些時候視圖繪製爲空矩形

這是我用來生成對話框的代碼。標題和消息有時顯示爲白色矩形(我假設這是因爲我使用了輕量級主題,否則我認爲它們會是黑色的)。

AlertDialog.Builder b = new AlertDialog.Builder(this); 
    b.setTitle(R.string.warning); 
    b.setMessage(R.string.want_to_close); 
    b.setPositiveButton(R.string.yes, ...); 
    b.setNegativeButton(R.string.no, ...); 
    b.show(); 
+0

您使用哪種語言?您是否使用不受支持的字符集? – Rajesh

+0

語言是斯洛文尼亞語,XML編碼是UTF-8 – user1407172

+0

你讓我覺得。我將嘗試用字符代碼 – user1407172

回答

0

要顯示警報消息,請參閱以下內容,

警報(的getString(R.string.warning)的getString(R.string.want_to_close));

public void Alert(String text, String title) 
    { 
     AlertDialog dialog=new AlertDialog.Builder(context).create(); 
     dialog.setTitle(title); 
     dialog.setMessage(text); 
     if(!title.equals("") && !text.equals("")) 
     { 
      dialog.setButton("OK", 
        new DialogInterface.OnClickListener() 
        { 
         public void onClick(DialogInterface dialog, int whichButton) 
         { 
          //Do anything 
         } 
        }); 
      dialog.setButton2("Cancel", 
        new DialogInterface.OnClickListener() 
        { 
         public void onClick(DialogInterface dialog, int whichButton) 
         { 
          //Do anything 
         } 
        }); 
     } 

     dialog.show(); 

    } 
+0

替換xml中的所有特殊字符,標題和文本不爲空,它們位於strings.xml中。 – user1407172

+0

您可以通過,R.string.warning作爲標題,R.string.want_to_close作爲消息 – Ponmalar

+0

對話框內部的視圖本身顯示爲白色空白矩形,但並非總是如此。大多數時候它顯示得很好 – user1407172

0

你需要得到來自BuilderAlertdialog對象,然後顯示。

AlertDialog.Builder b = new AlertDialog.Builder(this); 
b.setTitle(R.string.warning); 
b.setMessage(R.string.want_to_close); 
b.setPositiveButton(R.string.yes, ...); 
b.setNegativeButton(R.string.no, ...); 

AlertDialog alert = b.create(); 
alert.show(); 
+0

你是如何修復它的? – Ronnie

+0

你可以跳過create()它無論如何顯示 – user1407172