我一直在四处寻找,我找不到任何东西,所以我不知道它是否可能,但是有没有办法在关闭alertdialogs做一些事情?
在我的情况下,我将背景UI暂停,同时对话框显示为暂停屏幕.如果单击对话框中的按钮,它将运行onClick的东西,所以我在那里取消暂停,但如果他们点击对话框,它会关闭对话框,但不会运行onClick.无论如何,当他们点击一边时,有什么东西可以运行吗?谢谢!
我想将 EditText 字段限制为 150 个字符,这很容易做到。但是,当用户尝试超过该限制时,我还需要通过键入(即第 151 个字符)或粘贴超过 150 个字符来提醒用户。
解决这个问题的最佳方法是什么?
我想只在用户输入不为空时才启用alertDialog肯定按钮,如果用户输入为空则禁用它,为了验证目的切换为王,用户输入不能为空.这是我的代码,即使我把一个字符串按钮没有激活.
buildInfos.setPositiveButton(android.R.string.ok, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
infosDesc = inputInfos.getText().toString();
Log.i("DESC", infosDesc);
drawBetween2LastPoints(getAlertColor(alertType), "title", infosDesc);
}
});
AlertDialog buildInfosDialog = buildInfos.create();
buildInfosDialog.show();
if(infosDesc.isEmpty()){
buildInfosDialog.getButton(Dialog.BUTTON_POSITIVE).setEnabled(false);
}
Run Code Online (Sandbox Code Playgroud) 您好,我正在尝试显示带有复选框的警报对话框,以允许用户选择“不再显示此对话框”选项。对话框正在显示,但复选框没有显示。这是我的代码:
AlertDialog.Builder dialogBack;
dialogBack = new AlertDialog.Builder(this);
dialogBack.setTitle(context.getString(R.string.msg_attention));
dialogBack.setMessage(context.getString(R.string.msg_photo_caution));
dialogBack.setCancelable(false);
dialogBack.setPositiveButton(context.getString(R.string.confirm_continue),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogBack, int which) {
dialogBack.dismiss();
beginTakeSupervisorPhoto();
}
});
dialogBack.setNegativeButton(context.getString(R.string.confirm_cancel),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogBack, int which) {
dialogBack.dismiss();
}
});
final CharSequence[] items = {context.getString(R.string.msg_dont_show_again)};
dialogBack.setMultiChoiceItems(items, null,
new DialogInterface.OnMultiChoiceClickListener() {
public void onClick(DialogInterface dialog, int indexSelected,boolean isChecked) {
Log.e("ListaClientesActivity.java","isChecked: "+isChecked);
if (isChecked) {
showPhotoWarning = false;
dataUtil.putBoolean(Constantes.SHOW_PHOTO_WARNING, false);
}else{
showPhotoWarning = true;
dataUtil.putBoolean(Constantes.SHOW_PHOTO_WARNING, true);
}
dataUtil.savePreferences();
}
});
dialogBack.create().show();
Run Code Online (Sandbox Code Playgroud)
这很奇怪,因为当我在对话框中使用文本视图时它对我有用:
dialogBack.setView(myMsg);
Run Code Online (Sandbox Code Playgroud) 我找到了两个 SO 线程,它们告诉我如何在对象中居中标题和消息,AlertDialog并通过编写我希望能够调用以居中 any 的方法来伪造我的方式AlertDialog。它在手机和平板电脑上运行良好,甚至可以显示多行消息,无论是否带有'\n's。
public void showCenteredInfoDialog(TextView _title, TextView _message) {
_title.setGravity(Gravity.CENTER);
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setPositiveButton("OK", null);
builder.setCustomTitle(_title);
builder.setMessage(_message.getText());
AlertDialog dialog = builder.show();
TextView messageView = (TextView)
dialog.findViewById(android.R.id.message);
messageView.setGravity(Gravity.CENTER);
}
Run Code Online (Sandbox Code Playgroud)
我做了大量的定制——即,我对我的发现和所做的事情有一些线索——但有一行让我想知道:
TextView messageView = (TextView) dialog.findViewById(android.R.id.message);
什么是 android.R.id.message?
这是我能找到的所有相关文档:
android.R.id
public static final int message = 16908299
Run Code Online (Sandbox Code Playgroud)
我在哪里可以找到有关Android.R.id对象(以及更多)的更多文档?这似乎是一个可能的金矿。
在我的应用程序中,我将推送通知显示为一个对话框,其中有两个名为Yes和No的按钮。我需要显示对话框标题中运行的计时器(20秒)。
如果用户单击“ 是”,则应转到一个活动。
如果用户单击“ 否”,对话框将在计时器结束前被取消。
倒计时结束后,对话框应消失。我应该如何实施呢?
这是我的警报对话框方法
public void showAlertDialog(final Context context, String title, String message,
Boolean status) {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(context);
// Setting Dialog Title
alertDialog.setTitle(title);
// Setting Dialog Message
alertDialog.setMessage(message);
// Setting Icon to Dialog
//alertDialog.setIcon(R.drawable.fail);
// Setting Positive "Yes" Button
alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(), "You clicked on YES", Toast.LENGTH_SHORT).show();
}
});
// Setting Negative "NO" Button
alertDialog.setNegativeButton("NO", new DialogInterface.OnClickListener() {
public …Run Code Online (Sandbox Code Playgroud) 我已经设置了一个带有多个编辑文本的警报对话框,但我不确定如何存储在警报对话框中输入的值。
通常我可以按照以下方式做一些事情:
final EditText input = new EditText(this);
alert.setView(input);
Editable value = input.getText();
Run Code Online (Sandbox Code Playgroud)
但是我的 MessageDialog 是一个单独的类,从 SearchResult.java 像这样调用,所以我不知道如何访问 MyMessageDialog.java 中编辑文本的实例:
MyMessageDialog.displayMessage(SearchResult.this, "Sample Info", "Required");
有谁知道如何在此实现中检索编辑文本值?
这是 MyMessageDialog 类,下面是警报对话框的布局:
public class MyMessageDialog {
@SuppressLint("NewApi")
public static AlertDialog displayMessage(Context context, String title, String message){
AlertDialog.Builder builder = new AlertDialog.Builder(context);
LayoutInflater inflater = LayoutInflater.from(context);
builder.setTitle(title);
builder.setMessage(message);
builder.setView(inflater.inflate(R.layout.custom_view, null));
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builder.show();
return builder.create();
}
}
Run Code Online (Sandbox Code Playgroud)
警报对话框布局,custom_view:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout …Run Code Online (Sandbox Code Playgroud) android android-edittext layout-inflater android-alertdialog
只是一个简单的问题.我有一个警告对话框弹出窗口,为用户提供一个简短的选项列表.
我希望其中一个项目显示为粗体.这是我用于选项列表的基本代码.我希望"option1"是粗体,所有其他选项都是常规的.有没有办法在不使用自定义文本视图的情况下实现此目的?
CharSequence options[] = new CharSequence[] {"option1", "option2", "option3"};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Pick an option");
builder.setItems(options, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// my actions
}
});
builder.show();
Run Code Online (Sandbox Code Playgroud) 我目前正在使用需要使用大量AlertDialogs的应用程序.我目前在这里编写了一个基本编码:
protected void StopButton () {
AlertDialog.Builder StopDialog = new AlertDialog.Builder(MainActivity.this);
StopDialog.setTitle(R.string.Stop_Title);
StopDialog.setMessage(R.string.Stop_Message);
StopDialog.setPositiveButton(R.string.Yes_Button, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
((Protoype2) getApplication()).setRequestingLocationUpdates(false);
finish();
}
});
StopDialog.setNegativeButton(R.string.No_Button, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
((Protoype2) getApplication()).setRequestingLocationUpdates(true);
}
});
StopDialog.setNeutralButton(R.string.Negative_Button, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//Closes box
finish();
}
});
AlertDialog alert = StopDialog.create();
alert.show();
}
Run Code Online (Sandbox Code Playgroud)
StopButton工作,当我打电话时,Dialog会出现.但是,完成(); 功能不起作用.
经过审核,我发现finish(); 没有完成对话,而是完整的应用程序.我知道我需要在那里获得AlertDialog.cancel.
问题是:正如您所看到的,AlertDialog仅在StopDialog完成后创建.
如何在StopDialog完成之前设置AlertDialog.finish()?
我有这个 AlertDialog 和 AlertDialog.Builder:
String message = "A message";
AlertDialog.Builder dBuilder = new AlertDialog.Builder(this);
dBuilder.setMessage(message);
....
AlertDialog myDialog = dBuilder.create();
Run Code Online (Sandbox Code Playgroud)
现在我正在编写一个单元测试,需要测试对话框的消息。我如何访问该消息?