Dynamically set the theme of dialog if no theme styles are defined
Method One:
Alertdialog.builder Builder = new Alertdialog.builder (context,alertdialog.theme_holo_light);
Method Two:
////hack for no holo theme related----begin
int divierid = Dialog.getcontext (). Getresources ()
. Getidentifier ("Android:id/titledivider", NULL, NULL);
int titleid = Dialog.getcontext (). Getresources ()
. Getidentifier ("Android:id/alerttitle", NULL, NULL);
int panelid = Dialog.getcontext (). Getresources ()
. Getidentifier ("Android:id/parentpanel", NULL, NULL);
int toppanelid = Dialog.getcontext (). Getresources ()
. Getidentifier ("Android:id/toppanel", NULL, NULL);
dialog.show ();
View Decorview = (view) Dialog.getwindow (). Getdecorview ();
View Contentview = Decorview.findviewbyid (Android. R.id.content);
if (contentview! = null) {
Contentview.setontouchlistener (New Ontouchlistener () {
@Override
Public boolean OnTouch (View V, motionevent event) {
log.d (TAG, "touch Outside");
Dialog.dismiss ();
return false;
}
});
}
View toppanel = Dialog.findviewbyid (toppanelid);
if (toppanel! = null) {
Toppanel.setontouchlistener (New Ontouchlistener () {
@Override
Public boolean OnTouch (View V, motionevent event) {
log.d (TAG, "Touch Toppanel");
return true;
}
});
}
View dividerview = Dialog.findviewbyid (Divierid);
if (dividerview! = null)
Dividerview.setbackgroundcolor (Dialog.getcontext (). Getresources ()
. GetColor (r.color.holo_blue_light));
TextView alerttitle = (TextView) Dialog.findviewbyid (TitleID);
if (alerttitle! = null) {
Alerttitle.settextcolor (Dialog.getcontext (). Getresources ()
. GetColor (r.color.holo_blue_light));
alerttitle.settextsize (dimenutil.sp2px (10));
}
View parentpanel = Dialog.findviewbyid (panelid);
if (parentpanel! = null) {
Framelayout.layoutparams LP = (android.widget.FrameLayout.LayoutParams) parentpanel
. Getlayoutparams ();
if (LP! = NULL) {
lp.gravity = gravity.center;
parentpanel.setlayoutparams (LP);
}
}
ListView list = Dialog.getlistview ();
if (list! = null) {
arrayadapter<string> adapter = new Arrayadapter<string> (
Dialog.getcontext (), R.layout.dialog_list_item,
r.id.textview1, items);
List.setadapter (adapter);
}
////hack for no holo theme related----begin
Modify dialog Theme Properties