Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to change theme for AlertDialog
    primarykey
    data
    text
    <p>I was wondering if someone could help me out. I am trying to create a custom AlertDialog. In order to do this, I added the following line of code in styles.xml</p> <pre><code>&lt;resources&gt; &lt;style name="CustomAlertDialog" parent="android:Theme.Dialog.Alert"&gt; &lt;item name="android:windowBackground"&gt;@drawable/color_panel_background&lt;/item&gt; &lt;/style&gt; &lt;/resources&gt; </code></pre> <ul> <li>color_panel_background.9.png is located in drawable folder. This is also available in Android SDK res folder.</li> </ul> <p>The following is the main activity.</p> <pre><code>package com.customdialog; import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; import android.content.DialogInterface; import android.os.Bundle; public class CustomDialog extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); this.setTheme(R.style.CustomAlertDialog); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("HELLO!"); builder .setCancelable(false) .setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { //MyActivity.this.finish(); } }) .setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { //dialog.cancel(); } }); AlertDialog alertdialog = builder.create(); alertdialog.show(); } } </code></pre> <p>In order to apply the theme to an AlertDialog, I had to set the theme to the current context.</p> <p>However, I just can't seem to get the app to show customized AlertDialog. Can anyone help me out with this?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload