【问题标题】:How to set default theme to custom dialog box?如何将默认主题设置为自定义对话框?
【发布时间】:2016-05-10 08:56:58
【问题描述】:

我正在尝试为自定义对话框设置默认主题,但无法做到。我已经为我的 alertDialogs 设置了默认的“THEME_DEVICE_DEFAULT_LIGHT”,我想在我的自定义对话框中使用相同的主题。

我可以使用以下代码设置其他主题,但我无法使用 DEVICE_DEFAULT_LIGHT。

新的 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;
        }

【问题讨论】:

    标签: android dialog themes


    【解决方案1】:

    这样使用

    Dialog dialog = new Dialog(context,android.R.style.Theme_DeviceDefault_Light);
    

    【讨论】:

      猜你喜欢
      • 2018-05-16
      • 1970-01-01
      • 1970-01-01
      • 2014-09-14
      • 1970-01-01
      • 1970-01-01
      • 2020-10-23
      • 2011-09-03
      • 2016-04-15
      相关资源
      最近更新 更多