2016-05-10 125 views
0

我想設置一個默認主題到自定義對話框,但無法做到這一點。我已將默認的「THEME_DEVICE_DEFAULT_LIGHT」設置爲我的alertDialogs,並且我想將相同的主題用於我的自定義對話框。如何將默認主題設置爲自定義對話框?

我可以使用下面的代碼設置其他主題,但我無法使用DEVICE_DEFAULT_LIGHT。

new ContextThemeWrapper(context,R.style.MyTheme);

public static Dialog createSeatAssignmentDialog(final Context context, final SeatAssignmentCallback callback) { 
      final Dialog dialog = new Dialog(context); 
      dialog.setContentView(R.layout.assign_seat_dialog); 
      dialog.setTitle(R.string.assign_seat_dialog_title); 
      dialog.setOnKeyListener(DIALOG_ON_KEY_LISTENER); 
      new ContextThemeWrapper(context, R.style.Theme_AppCompat_Light_Dialog); 
      final EditText seat = (EditText) dialog.findViewById(R.id.seat_data); 
      final Button clearSeatData = (Button) dialog.findViewById(R.id.clear_seat_data); 
      final Button assignSeat = (Button) dialog.findViewById(R.id.assign_seat); 
      final Button cancel = (Button) dialog.findViewById(R.id.cancel_seat); 
      seat.setText(callback.getSeatNumber()); 
      clearSeatData.setOnClickListener(new View.OnClickListener() { 

       @Override 
       public void onClick(View view) { 
        seat.setText(""); 
       } 
      }); 
      assignSeat.setOnClickListener(new View.OnClickListener() { 

       @Override 
       public void onClick(View view) { 
        dialog.dismiss(); 
       } 
      }); 
      cancel.setOnClickListener(new View.OnClickListener() { 

       @Override 
       public void onClick(View view) { 
        dialog.cancel(); 
       } 
      }); 
      final SeatDialogHandler dialogEventHandler = new SeatDialogHandler(callback, seat); 
      dialog.setOnCancelListener(dialogEventHandler); 
      dialog.setOnDismissListener(dialogEventHandler); 
      dialog.setOnShowListener(dialogEventHandler); 
      dialog.show(); 
      return dialog; 
     } 

回答

0

使用這樣

Dialog dialog = new Dialog(context,android.R.style.Theme_DeviceDefault_Light); 
相關問題