android - How to customize style of AlertDialog across all versions? -
i try make custom style alert dialog work acros 2.2 4.2 versions. best approach found use
alertdialog.builder builder = new alertdialog.builder(new contextthemewrapper(this, r.style.alertdialogcustom));   however available api 11 not work on versions older that. suggest painless way implement alert dialog custom style? thanks.
you can use android-support-v4.jar (you can read library here)
add library in libs folder , add build path
now, creating dialog,
now convert extends activity fragmentactivity (it takes nothing, sub class of activity)
now have create static inside activity :
public static class reportnamefragment extends dialogfragment {      @override     public dialog oncreatedialog(bundle savedinstancestate) {         alertdialog.builder builder = new alertdialog.builder(getactivity());         builder.settitle(r.string.enter_report_name);          layoutinflater inflater = getactivity().getlayoutinflater();         view view = inflater.inflate(r.layout.enter_report_dialog, null);         final edittext reportname = (edittext) view                 .findviewbyid(r.id.report_name);         builder.setview(view)                 // add action buttons                 .setpositivebutton(r.string.save,                         new dialoginterface.onclicklistener() {                             @override                             public void onclick(dialoginterface dialog,                                     int id) {                                 //positive button task                              }                         })                 .setnegativebutton(r.string.cancel,                         new dialoginterface.onclicklistener() {                             public void onclick(dialoginterface dialog,                                     int id) {                                 reportnamefragment.this.getdialog()                                         .cancel();                             }                         });         return builder.create();     } }   and call dialog anywhere in activity writing :
dialogfragment reportnamefragment = new reportnamefragment();             reportnamefragment.show(getsupportfragmentmanager(),                     "reportnametypepicker");   if want read more dialogs, can go here...
Comments
Post a Comment