2013-07-30 24 views

回答

1

像這樣做,但做alert.show(),然後再改變顏色。

AlertDialog.Builder builder = new AlertDialog.Builder(this); 
      builder.setMessage("Stackoverflow answer!") 
      .setPositiveButton("YES", new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int id) { 
        dialog.cancel(); 
       } 
      }) 
      .setNegativeButton("NO", new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int id) { 
        dialog.cancel(); 
       } 
      }); 
      AlertDialog alert = builder.create(); 
      alert.show(); 
//Use R.id.button1 and button2 
    ((Button)alert.findViewById(android.R.id.button1)).setBackgroundResource("Set to what you want"); 
0

很抱歉,如果這個心不是你要找的答案,但是這是你如何做到這一點....

那是我不認爲你可以自定義默認警報對話,你將不得不作出像這樣的自定義提醒對話框。

定義這些爲全局變量

AlertDialog alertDialog; 
View promptsView; 
AlertDialog.Builder alertDialogBuilder; 

下面添加到任何導致alertdialogue出現

LayoutInflater li = LayoutInflater.from(this)); 

    View promptsView = li.inflate(R.layout.CustomLayout, null); 
    // above I am setting the customview of the alert dialogue 


    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
      getActivity()); 

    alertDialogBuilder.setView(promptsView); 
    // here I am officially setting the custom layout 

    // set dialog message 

    alertDialogBuilder.setTitle("Stretch Type"); 
    // alert dialogue title 

    // create alert dialog 
    alertDialog = alertDialogBuilder.create(); 

,併爲您CustomLayout.xml文件 只需添加一個TextView和兩個按鈕一個說法是其他不說,或任何你想對他們說