How to change theme for AlertDialog.
Posted
by Min Soo Kim
on Stack Overflow
See other posts from Stack Overflow
or by Min Soo Kim
Published on 2010-03-11T04:36:26Z
Indexed on
2010/03/11
4:39 UTC
Read the original article
Hit count: 1010
Hello everyone,
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
@drawable/color_panel_background
- color_panel_background.9.png is located in drawable folder. This is also available in Android SDK res folder.
The following is the main activity.
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();
}
}
In order to apply the theme to an AlertDialog, I had to set the theme to the current context.
However, I just can't seem to get the app to show customized AlertDialog. Can anyone help me out with this, and thank you very much in advance!
© Stack Overflow or respective owner