下面列出了android.app.AlertDialog#getWindow ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void showOptionDialog(final AlertDialog dialog) {
final IBinder windowToken = mKeyboardSwitcher.getMainKeyboardView().getWindowToken();
if (windowToken == null) {
return;
}
final Window window = dialog.getWindow();
final WindowManager.LayoutParams lp = window.getAttributes();
lp.token = windowToken;
lp.type = WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
window.setAttributes(lp);
window.addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
mOptionsDialog = dialog;
dialog.show();
}
private void showOptionDialog(final AlertDialog dialog) {
final IBinder windowToken = KeyboardSwitcher.getInstance().getMainKeyboardView().getWindowToken();
if (windowToken == null) {
return;
}
final Window window = dialog.getWindow();
final WindowManager.LayoutParams lp = window.getAttributes();
lp.token = windowToken;
lp.type = WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
window.setAttributes(lp);
window.addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
mOptionsDialog = dialog;
dialog.show();
}
private void showOptionDialog(final AlertDialog dialog) {
final IBinder windowToken = mKeyboardSwitcher.getMainKeyboardView().getWindowToken();
if (windowToken == null) {
return;
}
final Window window = dialog.getWindow();
final WindowManager.LayoutParams lp = window.getAttributes();
lp.token = windowToken;
lp.type = WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
window.setAttributes(lp);
window.addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
mOptionsDialog = dialog;
dialog.show();
}
private void showOptionDialog(final AlertDialog dialog) {
final IBinder windowToken = mKeyboardSwitcher.getMainKeyboardView().getWindowToken();
if (windowToken == null) {
return;
}
final Window window = dialog.getWindow();
final WindowManager.LayoutParams lp = window.getAttributes();
lp.token = windowToken;
lp.type = WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
window.setAttributes(lp);
window.addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
mOptionsDialog = dialog;
dialog.show();
}
private void showOptionDialog(final AlertDialog dialog) {
final IBinder windowToken = mKeyboardSwitcher.getMainKeyboardView().getWindowToken();
if (windowToken == null) {
return;
}
final Window window = dialog.getWindow();
final WindowManager.LayoutParams lp = window.getAttributes();
lp.token = windowToken;
lp.type = WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
window.setAttributes(lp);
window.addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
mOptionsDialog = dialog;
dialog.show();
}
private void showOptionDialog(final AlertDialog dialog) {
final IBinder windowToken = mKeyboardSwitcher.getMainKeyboardView().getWindowToken();
if (windowToken == null) {
return;
}
final Window window = dialog.getWindow();
final WindowManager.LayoutParams lp = window.getAttributes();
lp.token = windowToken;
lp.type = WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
window.setAttributes(lp);
window.addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
mOptionsDialog = dialog;
dialog.show();
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getContext()).setMessage(R.string.pair_disconnect);
// Set up the buttons
builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (mListener != null) {
mListener.onExitRoomSelected();
}
}
});
builder.setNeutralButton(R.string.cancel, null);
AlertDialog dialog = builder.show();
if (dialog.getWindow() != null) {
dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
}
setCancelable(false);
return dialog;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
int titleRes = getArguments().getInt(ARG_TITLE);
int messageRes = getArguments().getInt(ARG_MESSAGE);
AlertDialog.Builder builder = new AlertDialog.Builder(getContext()).setMessage(messageRes);
if (titleRes > -1) builder.setTitle(titleRes);
// Set up the buttons
builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (getArguments().getBoolean(ARG_EXIT_ON_OK) && mListener != null) {
mListener.exitApp();
}
}
});
AlertDialog dialog = builder.show();
if (dialog.getWindow() != null) {
dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
}
setCancelable(false);
return dialog;
}
private void showCopySeedAlert() {
// show the copy seed dialog
AlertDialog.Builder builder;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
builder = new AlertDialog.Builder(getContext(), android.R.style.Theme_Material_Light_Dialog_Alert);
} else {
builder = new AlertDialog.Builder(getContext());
}
Credentials credentials = realm.where(Credentials.class).findFirst();
if (credentials != null) {
AlertDialog dialog = builder.setTitle(R.string.settings_seed_alert_title)
.setMessage(clickedNewSeed ? credentials.getNewlyGeneratedSeed().replaceAll("(.{4})", "$1 ") : credentials.getSeed().replaceAll("(.{4})", "$1 "))
.setPositiveButton(R.string.settings_seed_alert_confirm_cta, (d, which) -> {
analyticsService.track(AnalyticsEvents.SEED_COPIED);
})
.setIcon(R.drawable.ic_warning)
.create();
dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
dialog.show();
if (dialog.getWindow() != null) {
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}
}
KeyboardUtil.hideKeyboard(getActivity());
}
public static AlertDialog buildBottomDialog(Activity activity, View contentView) {
AlertDialog dialog = new Builder(activity).create();
dialog.setCanceledOnTouchOutside(true);
dialog.show();
dialog.setContentView(contentView);
Window dialogWindow = dialog.getWindow();
Display d = activity.getWindowManager().getDefaultDisplay();
LayoutParams p = dialogWindow.getAttributes();
p.width = d.getWidth();
dialogWindow.setAttributes(p);
dialogWindow.setGravity(80);
return dialog;
}
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
View view = LayoutInflater.from(getContext())
.inflate(R.layout.location_dialog_fragment, mViewGroup, false);
initView(view);
AlertDialog.Builder builder = new AlertDialog.Builder(getContext())
.setIcon(R.drawable.ic_action_item_dialog)
.setView(view)
.setTitle("请输入信息")
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (TextUtils.isEmpty(mEditLocation.getText())) {
ToastUtil.show(getContext(), "未选择地点");
} else {
getLocationPlanData();
postSureCode(MapMarker.ADD);
}
}
})
.setNegativeButton("取消", null);
AlertDialog alertDialog = builder.create();
alertDialog.setOnCancelListener(null);
if (alertDialog.getWindow() != null) {
Window window = alertDialog.getWindow();
window.setWindowAnimations(R.style.dialogAnim);
}
return alertDialog;
}
private void colorAdjustment(AlertDialog dialog, ReadableMap colorMap) {
Window window = dialog.getWindow();
if (window != null) {
Button positiveButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
Button negativeButton = dialog.getButton(AlertDialog.BUTTON_NEGATIVE);
if (colorMap.hasKey("backgroundColor")) {
window.setBackgroundDrawable(new ColorDrawable(Color.parseColor(colorMap.getString("backgroundColor"))));
}
if (colorMap.hasKey("positiveButtonTextColor")) {
positiveButton.setTextColor(Color.parseColor(colorMap.getString("positiveButtonTextColor")));
}
if (colorMap.hasKey("positiveButtonBackgroundColor")) {
positiveButton.setBackgroundColor(Color.parseColor(colorMap.getString("positiveButtonBackgroundColor")));
}
if (colorMap.hasKey("negativeButtonTextColor")) {
negativeButton.setTextColor(Color.parseColor(colorMap.getString("negativeButtonTextColor")));
}
if (colorMap.hasKey("negativeButtonBackgroundColor")) {
negativeButton.setBackgroundColor(Color.parseColor(colorMap.getString("negativeButtonBackgroundColor")));
}
}
}
@Override
public AlertDialog create() {
AlertDialog dialog = super.create();
try {
if (dialog.getWindow() != null) {
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
int type = WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;
dialog.getWindow().setType(type);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return dialog;
}
private void caculatePos(AlertDialog dlg){
Window w = dlg.getWindow();
WindowManager.LayoutParams lp =w.getAttributes();
DisplayMetrics display = mMainActivity.getResources().getDisplayMetrics();
int dpi = display.densityDpi;
lp.width = 200*dpi/160;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
lp.y = -100;
w.setAttributes(lp);
}