2011-09-02 129 views
2

我已經創建了AlertDialog.Here我能夠更改AlertDialog按鈕的backgroundImage。現在是否可以在按鈕背後的區域背景圖像。我已經發送你的屏幕截圖..所以它會讓你清楚我想要什麼...以及我使用的代碼是..如何更改Alertdialog的背景圖像

 AlertDialog.Builder start_dialog = new AlertDialog.Builder(this); 

     TextView start_dialog_title = new TextView(this); 
     start_dialog_title.setText(m_res.getString(R.string.strt_dialog_title)); 
     start_dialog_title.setBackgroundResource(R.drawable.strt_dlg_tlt_bckgrnd); 
     start_dialog_title.setGravity(Gravity.CENTER); 
     start_dialog_title.setTextColor(Color.WHITE); 
     start_dialog_title.setTextSize(20);   

     TextView start_dialog_desc = new TextView(this); 
     start_dialog_desc.setText(Html.fromHtml(m_res.getString(R.string.strt_dialog_desc))); 
     start_dialog_desc.setPadding(10, 10, 10, 10); 
     start_dialog_desc.setBackgroundResource(R.drawable.strt_dlg_desc_bckgrnd); 
     start_dialog_desc.setGravity(Gravity.CENTER); 
     start_dialog_desc.setTextColor(Color.WHITE); 
     start_dialog_desc.setTextSize(15); 

     start_dialog.setCustomTitle(start_dialog_title); 
     start_dialog.setView(start_dialog_desc); 

     start_dialog.setPositiveButton("Ok", new DialogInterface.OnClickListener() 
     {         
      public void onClick(DialogInterface dialog, int id) 
      { 
       dialog.cancel(); 
      } 
     }); 

     AlertDialog alert = start_dialog.create(); 
     alert.show(); 
     ((Button)alert.findViewById(android.R.id.button1)).setBackgroundResource(R.drawable.settings_but); 

enter image description here

回答

0

不要設置肯定按鈕。在佈局文件中有自己的按鈕。這應該可以解決你的問題。

+0

是啊,我知道..但是這是不可能做到這裏..因爲我可以改變按鈕的背景圖像......它可能是一些選項,也 – AndroidDev

+0

我認爲沒有。搜索AlertDialog文檔,但dint找到它。 – Ronnie

0

是的,你可以但你必須定義你自己的按鈕,我建議你在xml中定義整個alertdialog並使用它。