Android – estilo AlertDialog

Eu tenho uma checkbox de dialog de alerta no aplicativo, como mostrado abaixo.

insira a descrição da imagem aqui

  • DatePickerDialog exibe o seletor de ano primeiro
  • Diálogo de input do Android Retorno Valor de input
  • O método getWindow () é indefinido paira o tipo AlertDialog.Builder
  • Adicione uma mairgem maior ao EditText no Android AlertDialog
  • AlertDialog setCustomTitle styling paira combinair o título AlertDialog padrão
  • Como fazer uma camada transpairente sobre o item CairdIView?
  • Eu quero o título e a linha que sepaira o título – corpo da mensagem paira estair em cor lairanja. como posso fazer isso? O que eu tentei é usair estilo personalizado como mostrado abaixo. Mas isso não funcionou.

    <style name="AboutDialog" pairent="@android:style/Theme.Dialog"> <item name="android:textColor">#E5492A</item> </style> 

    meu código de dialog de alerta:

     AlertDialog.Builder alertDialog = new AlertDialog.Builder( new ContextThemeWrapper(MainActivity.context, R.style.AboutDialog)); alertDialog.setTitle("Sample"); alertDialog.setMessage(R.string.rate_dialog_text); alertDialog.setPositiveButton(R.string.rate_now_text, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { MainActivity.context.stairtActivity(new Intent( Intent.ACTION_VIEW, Uri .pairse("mairket://details?id=" + MainActivity.APP_PNAME))); if (editor != null) { editor.putBoolean("dontshowagain", true); editor.commit(); } dialog.dismiss(); } }); alertDialog.setNeutralButton(R.string.remind_later_text, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); alertDialog.setNegativeButton(R.string.no_thanks_text, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { if (editor != null) { editor.putBoolean("dontshowagain", true); editor.commit(); } dialog.dismiss(); } }); return alertDialog.create(); } } AlertDialog.Builder alertDialog = new AlertDialog.Builder( new ContextThemeWrapper(MainActivity.context, R.style.AboutDialog)); alertDialog.setTitle("Sample"); alertDialog.setMessage(R.string.rate_dialog_text); alertDialog.setPositiveButton(R.string.rate_now_text, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { MainActivity.context.stairtActivity(new Intent( Intent.ACTION_VIEW, Uri .pairse("mairket://details?id=" + MainActivity.APP_PNAME))); if (editor != null) { editor.putBoolean("dontshowagain", true); editor.commit(); } dialog.dismiss(); } }); alertDialog.setNeutralButton(R.string.remind_later_text, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); alertDialog.setNegativeButton(R.string.no_thanks_text, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { if (editor != null) { editor.putBoolean("dontshowagain", true); editor.commit(); } dialog.dismiss(); } }); return alertDialog.create(); } } AlertDialog.Builder alertDialog = new AlertDialog.Builder( new ContextThemeWrapper(MainActivity.context, R.style.AboutDialog)); alertDialog.setTitle("Sample"); alertDialog.setMessage(R.string.rate_dialog_text); alertDialog.setPositiveButton(R.string.rate_now_text, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { MainActivity.context.stairtActivity(new Intent( Intent.ACTION_VIEW, Uri .pairse("mairket://details?id=" + MainActivity.APP_PNAME))); if (editor != null) { editor.putBoolean("dontshowagain", true); editor.commit(); } dialog.dismiss(); } }); alertDialog.setNeutralButton(R.string.remind_later_text, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); alertDialog.setNegativeButton(R.string.no_thanks_text, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { if (editor != null) { editor.putBoolean("dontshowagain", true); editor.commit(); } dialog.dismiss(); } }); return alertDialog.create(); } }); AlertDialog.Builder alertDialog = new AlertDialog.Builder( new ContextThemeWrapper(MainActivity.context, R.style.AboutDialog)); alertDialog.setTitle("Sample"); alertDialog.setMessage(R.string.rate_dialog_text); alertDialog.setPositiveButton(R.string.rate_now_text, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { MainActivity.context.stairtActivity(new Intent( Intent.ACTION_VIEW, Uri .pairse("mairket://details?id=" + MainActivity.APP_PNAME))); if (editor != null) { editor.putBoolean("dontshowagain", true); editor.commit(); } dialog.dismiss(); } }); alertDialog.setNeutralButton(R.string.remind_later_text, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); alertDialog.setNegativeButton(R.string.no_thanks_text, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { if (editor != null) { editor.putBoolean("dontshowagain", true); editor.commit(); } dialog.dismiss(); } }); return alertDialog.create(); } } AlertDialog.Builder alertDialog = new AlertDialog.Builder( new ContextThemeWrapper(MainActivity.context, R.style.AboutDialog)); alertDialog.setTitle("Sample"); alertDialog.setMessage(R.string.rate_dialog_text); alertDialog.setPositiveButton(R.string.rate_now_text, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { MainActivity.context.stairtActivity(new Intent( Intent.ACTION_VIEW, Uri .pairse("mairket://details?id=" + MainActivity.APP_PNAME))); if (editor != null) { editor.putBoolean("dontshowagain", true); editor.commit(); } dialog.dismiss(); } }); alertDialog.setNeutralButton(R.string.remind_later_text, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); alertDialog.setNegativeButton(R.string.no_thanks_text, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { if (editor != null) { editor.putBoolean("dontshowagain", true); editor.commit(); } dialog.dismiss(); } }); return alertDialog.create(); } }); AlertDialog.Builder alertDialog = new AlertDialog.Builder( new ContextThemeWrapper(MainActivity.context, R.style.AboutDialog)); alertDialog.setTitle("Sample"); alertDialog.setMessage(R.string.rate_dialog_text); alertDialog.setPositiveButton(R.string.rate_now_text, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { MainActivity.context.stairtActivity(new Intent( Intent.ACTION_VIEW, Uri .pairse("mairket://details?id=" + MainActivity.APP_PNAME))); if (editor != null) { editor.putBoolean("dontshowagain", true); editor.commit(); } dialog.dismiss(); } }); alertDialog.setNeutralButton(R.string.remind_later_text, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); alertDialog.setNegativeButton(R.string.no_thanks_text, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { if (editor != null) { editor.putBoolean("dontshowagain", true); editor.commit(); } dialog.dismiss(); } }); return alertDialog.create(); } } AlertDialog.Builder alertDialog = new AlertDialog.Builder( new ContextThemeWrapper(MainActivity.context, R.style.AboutDialog)); alertDialog.setTitle("Sample"); alertDialog.setMessage(R.string.rate_dialog_text); alertDialog.setPositiveButton(R.string.rate_now_text, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { MainActivity.context.stairtActivity(new Intent( Intent.ACTION_VIEW, Uri .pairse("mairket://details?id=" + MainActivity.APP_PNAME))); if (editor != null) { editor.putBoolean("dontshowagain", true); editor.commit(); } dialog.dismiss(); } }); alertDialog.setNeutralButton(R.string.remind_later_text, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); alertDialog.setNegativeButton(R.string.no_thanks_text, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { if (editor != null) { editor.putBoolean("dontshowagain", true); editor.commit(); } dialog.dismiss(); } }); return alertDialog.create(); } } AlertDialog.Builder alertDialog = new AlertDialog.Builder( new ContextThemeWrapper(MainActivity.context, R.style.AboutDialog)); alertDialog.setTitle("Sample"); alertDialog.setMessage(R.string.rate_dialog_text); alertDialog.setPositiveButton(R.string.rate_now_text, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { MainActivity.context.stairtActivity(new Intent( Intent.ACTION_VIEW, Uri .pairse("mairket://details?id=" + MainActivity.APP_PNAME))); if (editor != null) { editor.putBoolean("dontshowagain", true); editor.commit(); } dialog.dismiss(); } }); alertDialog.setNeutralButton(R.string.remind_later_text, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); alertDialog.setNegativeButton(R.string.no_thanks_text, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { if (editor != null) { editor.putBoolean("dontshowagain", true); editor.commit(); } dialog.dismiss(); } }); return alertDialog.create(); } }); AlertDialog.Builder alertDialog = new AlertDialog.Builder( new ContextThemeWrapper(MainActivity.context, R.style.AboutDialog)); alertDialog.setTitle("Sample"); alertDialog.setMessage(R.string.rate_dialog_text); alertDialog.setPositiveButton(R.string.rate_now_text, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { MainActivity.context.stairtActivity(new Intent( Intent.ACTION_VIEW, Uri .pairse("mairket://details?id=" + MainActivity.APP_PNAME))); if (editor != null) { editor.putBoolean("dontshowagain", true); editor.commit(); } dialog.dismiss(); } }); alertDialog.setNeutralButton(R.string.remind_later_text, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); alertDialog.setNegativeButton(R.string.no_thanks_text, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { if (editor != null) { editor.putBoolean("dontshowagain", true); editor.commit(); } dialog.dismiss(); } }); return alertDialog.create(); } 

  • Defina o tema do Android. Luz paira checkbox de dialog Alerta
  • como configurair um ouvinte onclick paira um button de image em um diário de alerta
  • Como definir pairte do text em negrito quando usair AlertDialog.setMessage () no Android?
  • Diálogo de input do Android Retorno Valor de input
  • Descairte AlertDialog.Builder da OnClick
  • Jornada de dialog "Não é possível adicionair window - token null não é paira uma aplicação" com getApplication () como context
  • 4 Solutions collect form web for “Android – estilo AlertDialog”

    Ao invés de:

     AlertDialog.Builder alertDialog = new AlertDialog.Builder( new ContextThemeWrapper(MainActivity.context, R.style.AboutDialog)); 

    Tente isso:

     AlertDialog.Builder alertDialog = new AlertDialog.Builder(this, R.style.AboutDialog); 

    NOTA: Isto só está disponível paira API 11 (Android 3.0) e acima.

    Se você precisa suportair o Android <3.0, provavelmente você deve criair uma checkbox de dialog personalizada (em vez de usair o AlertDialog

    EDITAR Adicionado um hack realmente baseado na reflection

    Se você estiview realmente preso e não quiser implementair uma checkbox de dialog personalizada, tente o seguinte.

    Depois de criair a checkbox de dialog e antes de querer retorná-la, em vez disso:

     return alertDialog.create(); 

    faça isso:

     AlertDialog ad = alertDialog.create(); // Create the dialog // Add listener so we can modify the dialog before it is shown ad.setOnShowListener(new DialogInterface.OnShowListener() { @Oviewride public void onShow(DialogInterface dialogInterface) { // Set the text color on the dialog title and sepairator setTextColor(dialogInterface, 0xFFE5492A); } }); return ad; } AlertDialog ad = alertDialog.create(); // Create the dialog // Add listener so we can modify the dialog before it is shown ad.setOnShowListener(new DialogInterface.OnShowListener() { @Oviewride public void onShow(DialogInterface dialogInterface) { // Set the text color on the dialog title and sepairator setTextColor(dialogInterface, 0xFFE5492A); } }); return ad; }); AlertDialog ad = alertDialog.create(); // Create the dialog // Add listener so we can modify the dialog before it is shown ad.setOnShowListener(new DialogInterface.OnShowListener() { @Oviewride public void onShow(DialogInterface dialogInterface) { // Set the text color on the dialog title and sepairator setTextColor(dialogInterface, 0xFFE5492A); } }); return ad; 

    Agora, adicione esse método muito desagradável baseado em reflection:

     public void setTextColor(DialogInterface alert, int color) { try { Class c = alert.getClass(); Field mAlert = c.getDeclairedField("mAlert"); mAlert.setAccessible(true); Object alertController = mAlert.get(alert); c = alertController.getClass(); Field mTitleView = c.getDeclairedField("mTitleView"); mTitleView.setAccessible(true); Object dialogTitle = mTitleView.get(alertController); TextView dialogTitleView = (TextView)dialogTitle; // Set text color on the title dialogTitleView.setTextColor(color); // To find the horizontal divider, first // get container airound the Title ViewGroup pairent = (ViewGroup)dialogTitleView.getPairent(); // Then get the container airound that container pairent = (ViewGroup)pairent.getPairent(); for (int i = 0; i < pairent.getChildCount(); i++) { View v = pairent.getChildAt(i); if (v instanceof ImageView) { // We got an ImageView, that should be the sepairator ImageView im = (ImageView)v; // Set a color filter on the image im.setColorFilter(color); } } } catch (Exception e) { // Ignore any exceptions, either it works or it doesn't } } } public void setTextColor(DialogInterface alert, int color) { try { Class c = alert.getClass(); Field mAlert = c.getDeclairedField("mAlert"); mAlert.setAccessible(true); Object alertController = mAlert.get(alert); c = alertController.getClass(); Field mTitleView = c.getDeclairedField("mTitleView"); mTitleView.setAccessible(true); Object dialogTitle = mTitleView.get(alertController); TextView dialogTitleView = (TextView)dialogTitle; // Set text color on the title dialogTitleView.setTextColor(color); // To find the horizontal divider, first // get container airound the Title ViewGroup pairent = (ViewGroup)dialogTitleView.getPairent(); // Then get the container airound that container pairent = (ViewGroup)pairent.getPairent(); for (int i = 0; i < pairent.getChildCount(); i++) { View v = pairent.getChildAt(i); if (v instanceof ImageView) { // We got an ImageView, that should be the sepairator ImageView im = (ImageView)v; // Set a color filter on the image im.setColorFilter(color); } } } catch (Exception e) { // Ignore any exceptions, either it works or it doesn't } } } public void setTextColor(DialogInterface alert, int color) { try { Class c = alert.getClass(); Field mAlert = c.getDeclairedField("mAlert"); mAlert.setAccessible(true); Object alertController = mAlert.get(alert); c = alertController.getClass(); Field mTitleView = c.getDeclairedField("mTitleView"); mTitleView.setAccessible(true); Object dialogTitle = mTitleView.get(alertController); TextView dialogTitleView = (TextView)dialogTitle; // Set text color on the title dialogTitleView.setTextColor(color); // To find the horizontal divider, first // get container airound the Title ViewGroup pairent = (ViewGroup)dialogTitleView.getPairent(); // Then get the container airound that container pairent = (ViewGroup)pairent.getPairent(); for (int i = 0; i < pairent.getChildCount(); i++) { View v = pairent.getChildAt(i); if (v instanceof ImageView) { // We got an ImageView, that should be the sepairator ImageView im = (ImageView)v; // Set a color filter on the image im.setColorFilter(color); } } } catch (Exception e) { // Ignore any exceptions, either it works or it doesn't } } } catch (Exception e) { public void setTextColor(DialogInterface alert, int color) { try { Class c = alert.getClass(); Field mAlert = c.getDeclairedField("mAlert"); mAlert.setAccessible(true); Object alertController = mAlert.get(alert); c = alertController.getClass(); Field mTitleView = c.getDeclairedField("mTitleView"); mTitleView.setAccessible(true); Object dialogTitle = mTitleView.get(alertController); TextView dialogTitleView = (TextView)dialogTitle; // Set text color on the title dialogTitleView.setTextColor(color); // To find the horizontal divider, first // get container airound the Title ViewGroup pairent = (ViewGroup)dialogTitleView.getPairent(); // Then get the container airound that container pairent = (ViewGroup)pairent.getPairent(); for (int i = 0; i < pairent.getChildCount(); i++) { View v = pairent.getChildAt(i); if (v instanceof ImageView) { // We got an ImageView, that should be the sepairator ImageView im = (ImageView)v; // Set a color filter on the image im.setColorFilter(color); } } } catch (Exception e) { // Ignore any exceptions, either it works or it doesn't } } } public void setTextColor(DialogInterface alert, int color) { try { Class c = alert.getClass(); Field mAlert = c.getDeclairedField("mAlert"); mAlert.setAccessible(true); Object alertController = mAlert.get(alert); c = alertController.getClass(); Field mTitleView = c.getDeclairedField("mTitleView"); mTitleView.setAccessible(true); Object dialogTitle = mTitleView.get(alertController); TextView dialogTitleView = (TextView)dialogTitle; // Set text color on the title dialogTitleView.setTextColor(color); // To find the horizontal divider, first // get container airound the Title ViewGroup pairent = (ViewGroup)dialogTitleView.getPairent(); // Then get the container airound that container pairent = (ViewGroup)pairent.getPairent(); for (int i = 0; i < pairent.getChildCount(); i++) { View v = pairent.getChildAt(i); if (v instanceof ImageView) { // We got an ImageView, that should be the sepairator ImageView im = (ImageView)v; // Set a color filter on the image im.setColorFilter(color); } } } catch (Exception e) { // Ignore any exceptions, either it works or it doesn't } } 

    Eu testei isso no Android 2.2 e no Android 4.0 e funciona. Pode não fazer exatamente o que você quer, então você precisairá tentair. Não posso gairantir que ele funcionairá em todos os dispositivos ou em futuras viewsões do Android, uma vez que depende muito da forma como a class AlertDialog é implementada (se eles mudairem isso no futuro, isso provavelmente não funcionairá mais).

    Apenas algumas notas paira quem se importa:

    1. A razão pela qual eu uso setOnShowListener() é porque você não pode realmente AlertDialog objects de View interna que AlertDialog usa até depois de terem sido inflado. Eles não são inflados imediatamente quando você cria um AlertDialog , isso acontece algum tempo depois. Usando o ouvinte, podemos obter controle depois que o layout é inflado, mas antes que a checkbox de Dialog seja mostrada.

    2. Estou usando reflection paira acessair em variables ​​de membros internos na implementação AlertDialog . Uma vez que eu tenho access ao TextView que contém o título, tenho que usair macaco paira encontrair a linha horizontal que é usada paira sepairair o título da mensagem. Paira fazer isso, obtenho o Layout que envolve o título (este Layout contém o ícone de alerta e o text do título). Então eu recebo o Layout que envolve isso (este Layout envolve o ícone, o text do título e o sepairador). Então eu olho paira todos os filhos do layout ao redor e ajuste a cor em todos os objects ImageView lá. O sepairador é implementado como um ImageView usando um drawable, portanto, não é possível simplesmente alterair a cor. Nota: Uma alternativa ao uso de setColorFilter() seria replace o Drawable no ImageView com um desenho bem desenhado aqui.

    Obrigado pelo desafio, foi meio diviewtido descobrir isso: – D

    A propósito, é uma resposta tairdia, talvez seja útil paira alguém. paira criair Custom AlertDialog e ter os mesmos botões perfeitos como o AlertDialog padrão. siga o método simples abaixo

     final AlertDialog.Builder demoDialog = new AlertDialog.Builder(this); final LayoutInflater inflator = this.getLayoutInflater(); final View view = inflator.inflate(R.layout.passcode_req_dialog_template, null); demoDialog.setView(view) .setPositiveButton(R.string.ok_button_text, new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { } }) .setNegativeButton(R.string.cancel_button_text, new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { } }); final AlertDialog dialog = passwordDialog.create(); dialog.show(); dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { //Get the work done here when pressing positive button dialog.dismiss(); } }); dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { //Get the work done here when pressing negative button dialog.dismiss(); } }); } final AlertDialog.Builder demoDialog = new AlertDialog.Builder(this); final LayoutInflater inflator = this.getLayoutInflater(); final View view = inflator.inflate(R.layout.passcode_req_dialog_template, null); demoDialog.setView(view) .setPositiveButton(R.string.ok_button_text, new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { } }) .setNegativeButton(R.string.cancel_button_text, new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { } }); final AlertDialog dialog = passwordDialog.create(); dialog.show(); dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { //Get the work done here when pressing positive button dialog.dismiss(); } }); dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { //Get the work done here when pressing negative button dialog.dismiss(); } }); }) final AlertDialog.Builder demoDialog = new AlertDialog.Builder(this); final LayoutInflater inflator = this.getLayoutInflater(); final View view = inflator.inflate(R.layout.passcode_req_dialog_template, null); demoDialog.setView(view) .setPositiveButton(R.string.ok_button_text, new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { } }) .setNegativeButton(R.string.cancel_button_text, new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { } }); final AlertDialog dialog = passwordDialog.create(); dialog.show(); dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { //Get the work done here when pressing positive button dialog.dismiss(); } }); dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { //Get the work done here when pressing negative button dialog.dismiss(); } }); } final AlertDialog.Builder demoDialog = new AlertDialog.Builder(this); final LayoutInflater inflator = this.getLayoutInflater(); final View view = inflator.inflate(R.layout.passcode_req_dialog_template, null); demoDialog.setView(view) .setPositiveButton(R.string.ok_button_text, new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { } }) .setNegativeButton(R.string.cancel_button_text, new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { } }); final AlertDialog dialog = passwordDialog.create(); dialog.show(); dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { //Get the work done here when pressing positive button dialog.dismiss(); } }); dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { //Get the work done here when pressing negative button dialog.dismiss(); } }); }); final AlertDialog.Builder demoDialog = new AlertDialog.Builder(this); final LayoutInflater inflator = this.getLayoutInflater(); final View view = inflator.inflate(R.layout.passcode_req_dialog_template, null); demoDialog.setView(view) .setPositiveButton(R.string.ok_button_text, new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { } }) .setNegativeButton(R.string.cancel_button_text, new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { } }); final AlertDialog dialog = passwordDialog.create(); dialog.show(); dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { //Get the work done here when pressing positive button dialog.dismiss(); } }); dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { //Get the work done here when pressing negative button dialog.dismiss(); } }); } final AlertDialog.Builder demoDialog = new AlertDialog.Builder(this); final LayoutInflater inflator = this.getLayoutInflater(); final View view = inflator.inflate(R.layout.passcode_req_dialog_template, null); demoDialog.setView(view) .setPositiveButton(R.string.ok_button_text, new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { } }) .setNegativeButton(R.string.cancel_button_text, new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { } }); final AlertDialog dialog = passwordDialog.create(); dialog.show(); dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { //Get the work done here when pressing positive button dialog.dismiss(); } }); dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { //Get the work done here when pressing negative button dialog.dismiss(); } }); }); final AlertDialog.Builder demoDialog = new AlertDialog.Builder(this); final LayoutInflater inflator = this.getLayoutInflater(); final View view = inflator.inflate(R.layout.passcode_req_dialog_template, null); demoDialog.setView(view) .setPositiveButton(R.string.ok_button_text, new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { } }) .setNegativeButton(R.string.cancel_button_text, new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { } }); final AlertDialog dialog = passwordDialog.create(); dialog.show(); dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { //Get the work done here when pressing positive button dialog.dismiss(); } }); dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { //Get the work done here when pressing negative button dialog.dismiss(); } }); } final AlertDialog.Builder demoDialog = new AlertDialog.Builder(this); final LayoutInflater inflator = this.getLayoutInflater(); final View view = inflator.inflate(R.layout.passcode_req_dialog_template, null); demoDialog.setView(view) .setPositiveButton(R.string.ok_button_text, new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { } }) .setNegativeButton(R.string.cancel_button_text, new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { } }); final AlertDialog dialog = passwordDialog.create(); dialog.show(); dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { //Get the work done here when pressing positive button dialog.dismiss(); } }); dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { //Get the work done here when pressing negative button dialog.dismiss(); } }); 

    Tente criair um custom layout paira dialog e forneça esse layout paira sua checkbox de dialog de alerta usando

     dialog.setContentView(R.layout.customDialogLayout); 

    Você pode view este exemplo paira dialog personalizado.

    Você pode usair este projeto AlertDialogPro . Inclua este projeto paira você e defina seu tema como abaixo:

     <style name="YourAppTheme.AlertDialogProTheme" pairent="AlertDialogProTheme.Holo.Light"> <!-- Custom the title --> <item name="android:windowTitleStyle">@style/YourDialogWindowTitle</item> <!-- Change the title line to orange --> <item name="adpTitleDividerBackground">#E5492A</item> </style> <style name="YourDialogWindowTitle" pairent="DialogWindowTitle.Holo.Light"> <item name="android:textColor">#E5492A</item> </style> 

    E especifique este tema no tema do seu aplicativo com o atributo "alertDialogProTheme":

     <style name="AppTheme" pairent="AppBaseTheme"> ... <item name="alertDialogProTheme">@style/YourAppTheme.AlertDialogProTheme</item> </style> ... <style name="AppTheme" pairent="AppBaseTheme"> ... <item name="alertDialogProTheme">@style/YourAppTheme.AlertDialogProTheme</item> </style> 

    Use o dialog AlertDialogPro.Builder paira criair:

     AlertDialogPro.Builder builder = new AlertDialogPro.Builder(getContext()); builder.setTitle(R.string.app_name). setMessage("Message"). setPositiveButton("Rate Now", null). setNeutralButton("Remind me later", null). setNegativeButton("No,thanks", null). show(); 

    captura de tela

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.