1

我想知道如何更改我的警報對話框上的灰色顏色?我曾嘗試過:如何更改AlertDialog視圖的背景顏色?

layout.setBackgroundResource(R.color.Aqua); 

它沒有工作。有任何想法嗎?

My AlertDialog

我創建AlertDialog用下面的代碼:

public class CustomInputDialog{ 

    private OnDialogClickListener listener; 
    private Context context; 
    private String title; 
    private String message; 
    EditText input; 
    LinearLayout layout; 

    public interface OnDialogClickListener { 
     void onDialogOKClick(String value); 
    } 

    public CustomInputDialog(String title, String message, Context context, OnDialogClickListener listener) { 

     super(); 
     this.title = title; 
     this.message = message; 
     this.context = context; 
     this.listener = listener; 

     layout = new LinearLayout(context); 
     layout.setOrientation(LinearLayout.VERTICAL); 
     LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); 
     params.setMargins(20, 10, 20, 10); 

     input = new EditText(context); 

     InputFilter[] filters = new InputFilter[1]; 
     filters[0] = new InputFilter.LengthFilter(20); 
     input.setFilters(filters); 

     layout.addView(input, params); 

    } 

    private void dialog(){ 

     AlertDialog.Builder builder = new AlertDialog.Builder(context); 
     builder.setCancelable(true); 
     builder.setView(layout); 
     builder.setTitle(title); 
     builder.setMessage(message); 
     builder.setInverseBackgroundForced(true); 
     builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { 
      @Override 
      public void onClick(DialogInterface dialog, int which) { 
       String value = input.getText().toString(); 
       listener.onDialogOKClick(value); 
       dialog.dismiss(); 
      } 
     }); 
     builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { 
       @Override 
       public void onClick(DialogInterface dialog, int which) { 
        dialog.dismiss(); 
       } 
     }); 
     AlertDialog alert = builder.create(); 
     alert.show(); 
    } 

} 
+0

http://stackoverflow.com/questions/13341560/how-to-create-a-custom-dialog-box-in -android/13342157#13342157 –

+0

你可以通過自定義對話框... – Piyush

+0

你檢查了任何答案或評論? –

回答

4

您可以設置自定義編程查看這樣的方式..

LayoutInflater inflater = getLayoutInflater(); 
View dialoglayout = inflater.inflate(R.layout.dialog_layout, (ViewGroup) getCurrentFocus()); 
AlertDialog.Builder builder = new AlertDialog.Builder(this); 
builder.setView(dialoglayout); 
builder.show(); 

然後後獲得分量的參考

e.g. Button btn = (Button) dialoglayout.findViewById(R.id.button_id); 
+0

查看我的問題http://stackoverflow.com/questions/23196053/set-app-widget-to-home-screen-programmatically – Piyush

0

你必須創建custom dialog使背景顏色的變化是指這link

0
<style name="AlertDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert"> 
    <item name="android:background">@color/myColor</item> 
</style> 

AlertDialog.Builder builder = new AlertDialog.Builder(Datetimeactivity.this,R.style.AlertDialogTheme);