How to make dialog look same in all versions from 2.2 to 4.4 and also in all tablets.i had created dialog which look perfect in 4.2 and i want same dialog to look in 2.3 also.How to make dialog look same in all versions from 2.2 to 4.4 and also in all tablets.i had created dialog which look perfect in 4.2 and i want same dialog to look 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 your code here to invoke YES event
if (deviceIsTablet(context)) { // if device is a
// tablet
if (isAppInstalled("com.skype.raider")) {
// insert what you want to do if device has
// skype
Intent intent = new Intent(
"android.intent.action.VIEW");
intent.setData(Uri.parse("skype:" + 123456789));
startActivity(intent);
} else {
// connect to 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 is not a 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 your code here to invoke NO event
}
});
// Showing Alert Message
alertDialog.show();
}
// determine whether or no the android device is a 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;
}
}