本文整理了Java中androidx.appcompat.app.AlertDialog.getButton()
方法的一些代码示例,展示了AlertDialog.getButton()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AlertDialog.getButton()
方法的具体详情如下:
包路径:androidx.appcompat.app.AlertDialog
类名称:AlertDialog
方法名:getButton
暂无
代码示例来源:origin: googlesamples/easypermissions
@Test
public void shouldPositiveListener_whenClickingPositiveButtonFromSupportFragment() {
AlertDialog alertDialog = new AppSettingsDialog.Builder(spyFragment)
.setTitle(TITLE)
.setRationale(RATIONALE)
.setPositiveButton(POSITIVE)
.setNegativeButton(NEGATIVE)
.setThemeResId(R.style.Theme_AppCompat)
.build()
.showDialog(positiveListener, negativeListener);
Button positive = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
positive.performClick();
verify(positiveListener, times(1))
.onClick(any(DialogInterface.class), anyInt());
}
代码示例来源:origin: googlesamples/easypermissions
@Test
public void shouldPositiveListener_whenClickingPositiveButtonFromActivity() {
AlertDialog alertDialog = new AppSettingsDialog.Builder(spyActivity)
.setTitle(TITLE)
.setRationale(RATIONALE)
.setPositiveButton(POSITIVE)
.setNegativeButton(NEGATIVE)
.setThemeResId(R.style.Theme_AppCompat)
.build()
.showDialog(positiveListener, negativeListener);
Button positive = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
positive.performClick();
verify(positiveListener, times(1))
.onClick(any(DialogInterface.class), anyInt());
}
代码示例来源:origin: googlesamples/easypermissions
@Test
public void shouldNegativeListener_whenClickingPositiveButtonFromSupportFragment() {
AlertDialog alertDialog = new AppSettingsDialog.Builder(spyFragment)
.setTitle(TITLE)
.setRationale(RATIONALE)
.setPositiveButton(POSITIVE)
.setNegativeButton(NEGATIVE)
.setThemeResId(R.style.Theme_AppCompat)
.build()
.showDialog(positiveListener, negativeListener);
Button positive = alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE);
positive.performClick();
verify(negativeListener, times(1))
.onClick(any(DialogInterface.class), anyInt());
}
代码示例来源:origin: googlesamples/easypermissions
@Test
public void shouldNegativeListener_whenClickingPositiveButtonFromActivity() {
AlertDialog alertDialog = new AppSettingsDialog.Builder(spyActivity)
.setTitle(TITLE)
.setRationale(RATIONALE)
.setPositiveButton(POSITIVE)
.setNegativeButton(NEGATIVE)
.setThemeResId(R.style.Theme_AppCompat)
.build()
.showDialog(positiveListener, negativeListener);
Button positive = alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE);
positive.performClick();
verify(negativeListener, times(1))
.onClick(any(DialogInterface.class), anyInt());
}
代码示例来源:origin: KeepSafe/TapTargetView
@Override
public void onSequenceCanceled(TapTarget lastTarget) {
final AlertDialog dialog = new AlertDialog.Builder(MainActivity.this)
.setTitle("Uh oh")
.setMessage("You canceled the sequence")
.setPositiveButton("Oops", null).show();
TapTargetView.showFor(dialog,
TapTarget.forView(dialog.getButton(DialogInterface.BUTTON_POSITIVE), "Uh oh!", "You canceled the sequence at step " + lastTarget.id())
.cancelable(false)
.tintTarget(false), new TapTargetView.Listener() {
@Override
public void onTargetClick(TapTargetView view) {
super.onTargetClick(view);
dialog.dismiss();
}
});
}
});
代码示例来源:origin: Gwokhov/Deadline
@Override
public void onShow(DialogInterface dialogInterface) {
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (TextUtils.isEmpty(mCategoryTextField.getText())) {
mCategoryTextField.setError(getString(R.string.category_empty));
} else {
sendResult(Activity.RESULT_OK, false, mCategoryTextField.getText().toString());
dismiss();
}
}
});
if (isNew) {
dialog.getButton(AlertDialog.BUTTON_NEUTRAL).setVisibility(View.GONE);
}
}
});
代码示例来源:origin: MCMrARM/revolution-irc
private void updateDialogOkButtonState() {
boolean isDataValid = (mRules.size() > 0);
for (int i = 0; i < mRules.size(); i++) {
Rule rule = mRules.get(i);
if (rule.reconnectDelay == -1 || (rule.repeatCount == -1 && i != mRules.size() - 1)) {
isDataValid = false;
break;
}
}
mCurrentOkButtonState = isDataValid;
mDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(isDataValid);
}
代码示例来源:origin: Gwokhov/Deadline
@Override
public void onShow(DialogInterface dialogInterface) {
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dialog.getButton(AlertDialog.BUTTON_NEUTRAL).setVisibility(View.GONE);
dialog.getButton(AlertDialog.BUTTON_NEUTRAL).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
代码示例来源:origin: Gwokhov/Deadline
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (isNew) {
for (String title : argCategories) {
if (title.equals(s.toString())) {
mCategoryTextField.setError(getString(R.string.category_exists));
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
} else {
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(true);
}
}
}
}
代码示例来源:origin: jruesga/rview
private void enabledOrDisableButtons(String value) {
if (getDialog() != null) {
final AlertDialog dialog = ((AlertDialog) getDialog());
Button button = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
if (button != null) {
button.setEnabled(
(!value.equals(mOriginalValue) || (value.isEmpty() && mModel.allowEmpty))
&& (!value.isEmpty() || (value.isEmpty() && mModel.allowEmpty))
&& (mRegExp == null || mRegExp.matcher(value).matches()));
}
}
}
}
代码示例来源:origin: jruesga/rview
private void enabledOrDisableButtons(String query) {
if (getDialog() != null) {
final AlertDialog dialog = ((AlertDialog) getDialog());
Button button = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
if (button != null) {
button.setEnabled(query.length() >= mBinding.reviewer.getThreshold());
}
}
}
}
代码示例来源:origin: jruesga/rview
private void enabledOrDisableButtons(String query) {
if (getDialog() != null) {
final AlertDialog dialog = ((AlertDialog) getDialog());
Button button = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
if (button != null) {
button.setEnabled(query.length() >= mBinding.assignee.getThreshold());
}
}
}
}
代码示例来源:origin: jruesga/rview
@Override
@SuppressLint("RestrictedApi")
public void setupDialog(Dialog dialog, int style) {
super.setupDialog(dialog, style);
dialog.setOnShowListener(dialog1 -> {
Button button = ((AlertDialog) dialog1).getButton(AlertDialog.BUTTON_POSITIVE);
button.setOnClickListener(v -> performAccountStateChanged());
});
}
代码示例来源:origin: bfabiszewski/ulogger-android
if (dialog != null) {
final EditText editText = dialog.findViewById(android.R.id.edit);
Button positiveButton = dialog.getButton(Dialog.BUTTON_POSITIVE);
if (editText != null && positiveButton != null) {
positiveButton.setOnClickListener(new View.OnClickListener() {
代码示例来源:origin: WireGuard/wireguard-android
@Override public void onResume() {
super.onResume();
final AlertDialog dialog = (AlertDialog) getDialog();
if (dialog != null) {
dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(v -> createTunnelAndDismiss());
setKeyboardVisible(true);
}
}
代码示例来源:origin: jruesga/rview
boolean enabledOrDisableButtons() {
if (getDialog() != null) {
final AlertDialog dialog = ((AlertDialog) getDialog());
Button button = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
if (button != null) {
boolean valid = isValidSelection() && isValidated();
button.setEnabled(valid);
return valid;
}
}
return false;
}
代码示例来源:origin: jaredrummler/ColorPicker
@Override public void onStart() {
super.onStart();
AlertDialog dialog = (AlertDialog) getDialog();
// http://stackoverflow.com/a/16972670/1048340
//noinspection ConstantConditions
dialog.getWindow()
.clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
// Do not dismiss the dialog when clicking the neutral button.
Button neutralButton = dialog.getButton(AlertDialog.BUTTON_NEUTRAL);
if (neutralButton != null) {
neutralButton.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
rootView.removeAllViews();
switch (dialogType) {
case TYPE_CUSTOM:
dialogType = TYPE_PRESETS;
((Button) v).setText(customButtonStringRes != 0 ? customButtonStringRes : R.string.cpv_custom);
rootView.addView(createPresetsView());
break;
case TYPE_PRESETS:
dialogType = TYPE_CUSTOM;
((Button) v).setText(presetsButtonStringRes != 0 ? presetsButtonStringRes : R.string.cpv_presets);
rootView.addView(createPickerView());
}
}
});
}
}
代码示例来源:origin: proninyaroslav/libretorrent
Button positiveButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
代码示例来源:origin: proninyaroslav/libretorrent
Button addButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
Button replaceButton = dialog.getButton(AlertDialog.BUTTON_NEGATIVE);
代码示例来源:origin: WireGuard/wireguard-android
@Override
public Dialog onCreateDialog(@Nullable final Bundle savedInstanceState) {
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());
alertDialogBuilder.setTitle(R.string.excluded_applications);
final AppListDialogFragmentBinding binding = AppListDialogFragmentBinding.inflate(getActivity().getLayoutInflater(), null, false);
binding.executePendingBindings();
alertDialogBuilder.setView(binding.getRoot());
alertDialogBuilder.setPositiveButton(R.string.set_exclusions, (dialog, which) -> setExclusionsAndDismiss());
alertDialogBuilder.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
alertDialogBuilder.setNeutralButton(R.string.deselect_all, (dialog, which) -> {
});
binding.setFragment(this);
binding.setAppData(appData);
loadData();
final AlertDialog dialog = alertDialogBuilder.create();
dialog.setOnShowListener(d -> dialog.getButton(DialogInterface.BUTTON_NEUTRAL).setOnClickListener(view -> {
for (final ApplicationData app : appData)
app.setExcludedFromTunnel(false);
}));
return dialog;
}
内容来源于网络,如有侵权,请联系作者删除!