2013-03-20 52 views
0

我有一個標題和圖像的alertbuilder:alertbuilder,未顯示標題

​​

我檢查這個問題是不是在標題,在圖像中,因爲如果我發表意見的setIcon線則顯示標題。

+0

凡從叫這個代碼? R.string.pull的價值是什麼?並且該對話框的屏幕截圖也將很有用。 – Egor 2013-03-20 09:15:16

+0

嘿setTitle直接'alert.setTitle(「Yourtext」);' – androidgeek 2013-03-20 09:16:40

+0

我試過了,但它不起作用 – user1256477 2013-03-20 09:18:32

回答

1

使用此片段修復它!

new AlertDialog.Builder(getApplicationContext()) 
          .setIcon(android.R.drawable.ic_dialog_info) 
          .setTitle(getResources().getString(R.string.pull)) 
          .setCancelable(false) 
          .setMessage("Quistion???") 
          .setPositiveButton("Yes", 
            new DialogInterface.OnClickListener() { 
             public void onClick(
               DialogInterface dialog, 
               int which) { 

             } 

            }) 
          .setNegativeButton("No", 
            new DialogInterface.OnClickListener() { 
             public void onClick(
               DialogInterface dialog, 
               int which) { 

             } 
            }).show(); 
+0

這並沒有強調他做錯了什麼,只是向他展示了他已經做了什麼。 – Doomsknight 2013-03-20 09:26:12

+0

http://developer.android.com/reference/android/app/AlertDialog.Builder.html#setTitle(int)。這不是一個答案,因爲setTitle可以採用resourceID。 – Raghunandan 2013-03-20 09:30:14

+0

getResources()。getString(R.string.pull) – XEENA 2013-03-20 09:32:37

1

你必須使用這樣的:

AlertDialog.Builder builder = new AlertDialog.Builder(this); 
      builder.setTitle(getResources().getString(R.string.pull)); 
      builder.setIcon(R.drawable.ic_action_search); 
      builder.setPositiveButton("OK", 
        new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, int id) { 
          // actions 
         } 
        }); 
      AlertDialog dialog = builder.create(); 
      dialog.show(); 

尤爾標題LL現在顯示...

+0

不,對不起,這沒有工作 – user1256477 2013-03-20 09:49:35