android - How to make dialog look same in all versions from 2.2 to 4.4 and also in all tablets -
how make dialog same in versions 2.2 4.4 , in tablets.i had created dialog perfect in 4.2 , want same dialog in 2.3 also.how make dialog same in versions 2.2 4.4 , in tablets.i had created dialog perfect in 4.2 , want same dialog in 2.3 also.
public class mainactivity extends activity { private context context; private textview textview; private dialog dialog; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); context = mainactivity.this; alertdialog.builder alertdialog = new alertdialog.builder( mainactivity.this); layoutinflater inflater = mainactivity.this.getlayoutinflater(); alertdialog.setview(inflater.inflate(r.layout.dialog_textview, null)); // setting positive "yes" button alertdialog.setpositivebutton("call", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int which) { // write code here invoke yes event if (deviceistablet(context)) { // if device // tablet if (isappinstalled("com.skype.raider")) { // insert want if device has // skype intent intent = new intent( "android.intent.action.view"); intent.setdata(uri.parse("skype:" + 123456789)); startactivity(intent); } else { // connect play store or whatever startactivity(new intent( intent.action_view, uri.parse("http://play.google.com/store/apps/details?id=com.skype.raider"))); } } else { // if device not tablet intent callintent = new intent(intent.action_call); callintent.setdata(uri.parse("tel:123456789")); startactivity(callintent); } } }); // setting negative "no" button alertdialog.setnegativebutton("cancel", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int which) { // write code here invoke no event } }); // showing alert message alertdialog.show(); } // determine whether or no android device tablet or not public static boolean deviceistablet(context c) { resources res = c.getresources(); return (res.getconfiguration().screenlayout & configuration.screenlayout_size_mask) >= configuration.screenlayout_size_large; } private boolean isappinstalled(string apptocheck) { packagemanager pm = getpackagemanager(); boolean isondevice = false; try { pm.getpackageinfo(apptocheck, packagemanager.get_activities); isondevice = true; } catch (packagemanager.namenotfoundexception exception) { isondevice = false; } return isondevice; }
}
check below links create custom dialog :
steps create custom dialog :
- create layout file (eg dialog.xml)
- reference dialog.xml class activity.
- bundle new layout file view of dialog box.
- display dialog.
Comments
Post a Comment