这似乎是一个非常简单的问题,但我搜索过,我找不到任何解决方案.我有一个包含内容的Dialog,就像这样:

我想改变对话框标题"输入密码"的颜色.我该怎么做?
在AlertDialog中,我可以设置Message的大小,但是当我为Title执行相同操作时,它会崩溃.
码:
AlertDialog dialog = new AlertDialog.Builder(this).setMessage(message).setTitle(title)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
}).show();
TextView titleTxt= (TextView)dialog.findViewById(android.R.id.title);
**titleTxt.setTextSize(TypedValue.COMPLEX_UNIT_SP, 40);** // crash here
TextView textView = (TextView) dialog.findViewById(android.R.id.message);
**textView.setTextSize(40);** // works fine
Button btn1 = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
btn1.setTextSize(36);
Run Code Online (Sandbox Code Playgroud)
我的输出:
05-10 11:49:56.917: E/AndroidRuntime(8376): FATAL EXCEPTION: main
05-10 11:49:56.917: E/AndroidRuntime(8376): java.lang.NullPointerException
05-10 11:49:56.917: E/AndroidRuntime(8376): at com.binary.taxitop.LoginScreen.showAlertDialog(LoginScreen.java:116)
05-10 11:49:56.917: E/AndroidRuntime(8376): at com.binary.taxitop.LoginScreen.VerifyCredentialsAndEnterNextScreen(LoginScreen.java:103)
05-10 11:49:56.917: E/AndroidRuntime(8376): at com.binary.taxitop.LoginScreen.onClick(LoginScreen.java:84)
05-10 11:49:56.917: E/AndroidRuntime(8376): at android.view.View.performClick(View.java:3511)
05-10 11:49:56.917: E/AndroidRuntime(8376): at android.view.View$PerformClick.run(View.java:14109)
05-10 …Run Code Online (Sandbox Code Playgroud) 我是Android的新手,我正在练习创建一个进度对话框.我想每隔几秒更改一次对话框中的消息,但是当我更改消息时,我的应用程序崩溃了.我有什么想法可能做错了吗?
private void progressDialogTest(final ArrayList<String> messages)
{
AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>()
{
private ProgressDialog progressDialog;
@Override
protected void onPreExecute()
{
progressDialog = new ProgressDialog(MainActivity.this);
progressDialog.setTitle("Progress Dialog");
progressDialog.show();
}
@Override
protected Void doInBackground(Void... arg0)
{
try
{
for(int i=0; i<messages.size(); i++)
{
/******** APPLICATION SEEMS TO CRASH AT LINE BELOW ********/
progressDialog.setMessage(messages.get(i));
Thread.sleep(3000);
}
}
catch (InterruptedException e)
{
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result)
{
progressDialog.dismiss();
}
};
task.execute((Void[])null);
}
Run Code Online (Sandbox Code Playgroud)

我想在按下后退按钮时向用户显示一个警报对话框。例如:您确定要退出吗?我在创建警报对话框时没有遇到问题。我在在哪里调用此对话框方法()。
这是我的 HomeScreen.java
public class HomeScreen extends TabActivity {
ConferenceOpenHelper helper_ob;
Cursor cursorHome;
ProfileEditScreen profileEditScreen;
ConferenceAdapter adapter;
EcMeeting meeting;
final Context context = this;
public static int HOMETEMP = 1;// Constant for Deleting the last created id
// in edit profile screen (Cancel)
public static String HOME = "home";// constant for updating status column
public static String CUSTOM_DIALER = "custom";
public static String TEMPLATE = "template";// constant for updating status // column
public static TabHost tabHost;
public static final int …Run Code Online (Sandbox Code Playgroud) 在我的Android应用程序中,我必须在按钮单击事件上弹出一个对话框.但是,当我点击按钮时,应用程序停止工作.我将预先设计的布局加载到对话框中.我将发布一个代码段.
Button login = (Button) findViewById(R.id.btn_login);
login.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final Dialog dialog = new Dialog(getApplication());
dialog.setContentView(R.layout.journey_details);
dialog.setTitle("Android Custom Dialog Box");
Button dialogButton = (Button) dialog.findViewById(R.id.btn_start_jrny);
dialogButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
});
Run Code Online (Sandbox Code Playgroud)
它在Log cat中显示以下错误.
E/AndroidRuntime(1412): FATAL EXCEPTION: main
E/AndroidRuntime(1412): Process: com.xont.geotracker, PID: 1412
E/AndroidRuntime(1412): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not …Run Code Online (Sandbox Code Playgroud) 我正在使用带有多项选择的 AlertDialog 来显示可检查项目的列表。
当用户选择某些值时,我可以获取它们的索引并将其保存到列表中。效果很好。
但我希望当用户再次打开 AlertDialog 时选择/检查他之前选择的值。
这是代码:
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMultiChoiceItems(R.array.array_cousine, null,
new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int indexSelected,
boolean isChecked) {
if (isChecked) {
seletedItems.add(++indexSelected);
} else if (seletedItems.contains(indexSelected)) {
seletedItems.remove(Integer.valueOf(++indexSelected));
}
}
})
// Set the action buttons
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
String[] expList = getResources().getStringArray(R.array.array_cousine);
for (int i = 0; i < seletedItems.size(); i++) {
int selected = seletedItems.get(i);
String selectedString = expList[selected …Run Code Online (Sandbox Code Playgroud) 里面的简单代码MainActivity.java创建一个警告对话框:
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
alertDialogBuilder.setTitle("Your Title")
.setMessage("Click yes or exit")
.setCancelable(false)
.setIcon(R.drawable.icon)
.setPositiveButton("Yes",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id ){
Log.v(" yes id = ",id+"");
MainActivity.this.finish();
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int id){
Log.v(" no id = ",id+"");
dialog.cancel();
}
});
AlertDialog alertDialog= alertDialogBuilder.create();
alertDialog.show();
Run Code Online (Sandbox Code Playgroud)
单击yes按钮显示在logcat中:yes id =:-1,no按钮同样显示:no id =:-2
因此,如何在参数值id内onClick法确定的?
我在活动上有一个按钮,通过调用此方法,我可以在该按钮上打开自定义对话框
public void openHcoDialog(View v) {
HcoDialog hcoDiag = new HcoDialog();
// Supply cityCode input as an argument.
Bundle args = new Bundle();
args.putString("cityCode", cityCode);
hcoDiag.setArguments(args);
hcoDiag.show(getSupportFragmentManager(), "hco dialog");
}
Run Code Online (Sandbox Code Playgroud)
在这个 HcoDialog 类中,我将扩展 DialogFragment 扩展为
public class HcoDialog extends DialogFragment {
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.hco_dialog, null);
builder.setView(view);
builder.setCancelable(true);
builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
Toast.makeText(getActivity(), "Toast 1", Toast.LENGTH_LONG).show();
progressDialog.dismiss();
} …Run Code Online (Sandbox Code Playgroud) 我正在比较字符串,如果全部相等则必须显示一个对话框"ALL ARE EQUAL",否则另一个对话框"NOT EQUAL".我想在Alert Dialog中只使用OK按钮.我的代码:
if(s1.equals("yes") && s2.equals("yes") && s3.equals("yes") && s4.equals("yes"))
showA();
Run Code Online (Sandbox Code Playgroud)
showA()方法在哪里
private void showA() {
AlertDialog.Builder ab = new AlertDialog.Builder(this);
ab.setTitle("Hello!!");
ab.setMessage("ALL ARE EQUAL");
ab.setCancelable(false);
ab.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
AlertDialog ad = ab.create();
ad.show();
}
Run Code Online (Sandbox Code Playgroud) 我想创建一个像 Android 游戏的第一个图像一样的自定义对话框。经过大量的试验和错误,我能够创建一个看起来像第二个屏幕截图图像的对话框。
即使它看起来与我想要实现的相同,但即使它是 png,它也会在图像周围显示白色像素。
如何从屏幕截图对话框图像中删除白色像素并使其看起来与第一张图像相同?
我有这个问题:
\n\nBuilder\n(android.content.Context)\nin Builder\xc2\xa0cannot be applied\nto\n(anonymous android.content.DialogInterface.OnClickListener)\nRun Code Online (Sandbox Code Playgroud)\n\n在此代码上:
\n\nAlertDialog ventana;\n ventana=new AlertDialog.Builder(this).create();\n ventana.setTitle("COBARDE");\n ventana.setMessage("Rendidse es de debiles,a seguir jugando");\n ventana.show();\n ventana.setButton(8,"Confirmar", new DialogInterface.OnClickListener() {\n public void onClick(DialogInterface dialogo1, int id) {\n aceptar();\n }\n public void aceptar(){\n AlertDialog ventana2;\n ventana2=new AlertDialog.Builder(this).create();\n ventana2.setTitle("puto");\n ventana2.setMessage("Rendidse es de debiles,a seguir jugando");\n ventana2.show();\n }\n\n });\nRun Code Online (Sandbox Code Playgroud)\n\n有人可以解决这个问题吗?我正在尝试将一个警报对话框放入另一个警报对话框中
\n