下面列出了android.content.DialogInterface#OnDismissListener ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void showDialogWithHtmlTextView(@StringRes int resTitleId, String text, boolean isHtml, DialogInterface.OnDismissListener dismissedListener) {
ScrollView scroll = new ScrollView(_context);
AppCompatTextView textView = new AppCompatTextView(_context);
int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 16, _context.getResources().getDisplayMetrics());
scroll.setPadding(padding, 0, padding, 0);
scroll.addView(textView);
textView.setMovementMethod(new LinkMovementMethod());
textView.setText(isHtml ? new SpannableString(Html.fromHtml(text)) : text);
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 17);
AlertDialog.Builder dialog = new AlertDialog.Builder(_context)
.setPositiveButton(android.R.string.ok, null).setOnDismissListener(dismissedListener)
.setView(scroll);
if (resTitleId != 0) {
dialog.setTitle(resTitleId);
}
dialogFullWidth(dialog.show(), true, false);
}
public Dialog setOnDismissListener(DialogInterface.OnDismissListener onDismissListener) {
mOnDismissListener = onDismissListener;
setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialogInterface) {
if (mOnDismissListener != null) {
mOnDismissListener.onDismiss(dialogInterface);
}
}
});
return this;
}
private void showRationale(DialogInterface.OnDismissListener listener) {
PermissionCallback callback = PermissionUtil.getCallback();
String title = getCallbackTitle(callback);
String message = getCallbackMessage(callback);
AlertDialog dialog = new AlertDialog.Builder(this,R.style.Theme_AppCompat_Light_Dialog_MinWidth)
.setTitle(title)
.setMessage(message)
.setPositiveButton(android.R.string.ok, null)
.setOnDismissListener(listener)
.create();
dialog.show();
}
/**
* 设置一个销毁监听器
*
* @param listener 销毁监听器对象
* @deprecated 请使用 {@link #addOnDismissListener(BaseDialog.OnDismissListener)}
*/
@Deprecated
@Override
public void setOnDismissListener(@Nullable DialogInterface.OnDismissListener listener) {
if (listener == null) {
return;
}
addOnDismissListener(new DismissListenerWrapper(listener));
}
public static Dialog showTips(Context context, String title, String des, String btn, DialogInterface.OnDismissListener dismissListener) {
AlertDialog.Builder builder = dialogBuilder(context, title, des);
builder.setCancelable(true);
builder.setPositiveButton(btn, null);
Dialog dialog = builder.show();
dialog.setCanceledOnTouchOutside(true);
dialog.setOnDismissListener(dismissListener);
return dialog;
}
public static Dialog createProgressDialog(Context context, String title, String des, DialogInterface.OnDismissListener dismissListener,boolean cancelable) {
ProgressDialog builder = dialogBuilder(context, title, des);
builder.setCancelable(cancelable);
builder.setCanceledOnTouchOutside(true);
builder.setOnDismissListener(dismissListener);
return builder;
}
public static DialogFragment myAppInstall(String appName, DialogInterface.OnClickListener okListener, DialogInterface.OnDismissListener dismissListener) {
// DialogFragment fragment = MyAppInstallDialog.newInstance(appName, okListener, dismissListener);
//
// Bundle bundle = new Bundle();
//
// bundle.putString("appName", appName);
// fragment.setArguments(bundle);
return MyAppInstallDialog.newInstance(appName, okListener, dismissListener);
}
public static AlertDialog showInfoDialog(Context context, CharSequence message, DialogInterface.OnClickListener onClickListener,
DialogInterface.OnDismissListener onDismissListener) {
AlertDialog alertDialog = new AlertDialog.Builder(context)
.setTitle("sample")
.setMessage(message)
.setPositiveButton(R.string.text_ok, onClickListener)
.setOnDismissListener(onDismissListener)
.create();
alertDialog.show();
return alertDialog;
}
public static Dialog dialogBuilder(CharSequence message, DialogInterface.OnClickListener negativeListener,
DialogInterface.OnClickListener positiveListener,
DialogInterface.OnDismissListener dismissListener, Context context) {
Dialog dialog = new Dialog(context).setMessage(message);
if (negativeListener != null) {
dialog.setNegativeButton(context.getString(R.string.cancel), negativeListener);
}
if (positiveListener != null) {
dialog.setPositiveButton(context.getString(R.string.ok), positiveListener);
}
if (dismissListener != null) {
dialog.setOnDismissListener(dismissListener);
}
return dialog;
}
public static MyAppInstallDialog newInstance(String appName, DialogInterface.OnClickListener okListener, DialogInterface.OnDismissListener dismissListener) {
MyAppInstallDialog dialog = new MyAppInstallDialog();
dialog.appName = appName;
dialog.okListener = okListener;
dialog.dismissListener = dismissListener;
return dialog;
}
public void setOnDismissListener(DialogInterface.OnDismissListener onDismissListener) {
mOnDismissListener = onDismissListener;
}
/** Returns and shows the dialog with ok/cancel button. */
public AlertDialog showDialog() {
// Only show one dialog at a time.
if (dialog != null && dialog.isShowing()) {
return dialog;
}
final DialogInterface.OnClickListener onClickListener =
(dialog, buttonClicked) -> clickDialogInternal(buttonClicked);
final DialogInterface.OnDismissListener onDismissListener = dialog -> dismissDialogInternal();
AlertDialog.Builder dialogBuilder =
new AlertDialog.Builder(context)
.setTitle(dialogTitleResId)
.setNegativeButton(android.R.string.cancel, onClickListener)
.setPositiveButton(android.R.string.ok, onClickListener)
.setOnDismissListener(onDismissListener)
.setCancelable(true);
String message = getMessageString();
if (!TextUtils.isEmpty(message)) {
dialogBuilder.setMessage(message);
}
View customizedView = getCustomizedView();
if (customizedView != null) {
dialogBuilder.setView(customizedView);
}
dialog = dialogBuilder.create();
if (isSoftInputMode) {
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
}
if (context instanceof TalkBackService) {
DialogUtils.setWindowTypeToDialog(dialog.getWindow());
} else {
LogUtils.v(
TAG,
"Create BaseDialog from context not instance of TalkBackService, class:"
+ context.getClass());
}
dialog.show();
registerServiceDialog();
return dialog;
}
public ChangeLogDialog setOnDismissListener(final DialogInterface.OnDismissListener onDismissListener) {
mOnDismissListener = onDismissListener;
return this;
}
public static Dialog showTips(Context context, int title, int des, int btn, DialogInterface.OnDismissListener dismissListener) {
return showTips(context, context.getString(title), context.getString(des), context.getString(btn), dismissListener);
}
public Builder setOnDismissListener(DialogInterface.OnDismissListener onDismissListener) {
mParams.mOnDismissListener = onDismissListener;
return this;
}
@SuppressWarnings("unused")
public void setOnDismissListener(DialogInterface.OnDismissListener onDismissListener) {
mOnDismissListener = onDismissListener;
}
public static Dialog createProgressDialog(Context context, int title, int des, int btn, DialogInterface.OnDismissListener dismissListener,boolean cancelable) {
return createProgressDialog(context, context.getString(title), context.getString(des), dismissListener,cancelable);
}
@SuppressWarnings("unused")
public void setOnDismissListener(DialogInterface.OnDismissListener onDismissListener) {
mOnDismissListener = onDismissListener;
}
@SuppressWarnings("unused")
public void setOnDismissListener(DialogInterface.OnDismissListener onDismissListener) {
mOnDismissListener = onDismissListener;
}
/**
* Sets the listener, which should be notified, when the dialog, which is created by the
* builder, is dismissed for any reason.
*
* @param listener
* The listener, which should be set, as an instance of the type {@link
* DialogInterface.OnDismissListener}, or null, if no listener should be set
* @return The builder, the method has been called upon, as an instance of the generic type
* BuilderType
*/
public final BuilderType setOnDismissListener(
@Nullable final DialogInterface.OnDismissListener listener) {
getProduct().setOnDismissListener(listener);
return self();
}