Advertisement
Guest User

Untitled

a guest
Jul 20th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. public void showDialog(final String title, final String message,
  2. final OnClickListener onClickPositive,
  3. final OnClickListener onCLickNegative, final String positiveButton,
  4. final String negativeButton, final boolean cancelable) {
  5. if (!isFinishing()) {
  6. runOnUiThread(new Runnable() {
  7.  
  8. @Override
  9. public void run() {
  10.  
  11. if (dialog != null && dialog.isShowing()) {
  12. dialog.cancel();
  13. }
  14.  
  15. Builder builder;
  16. if (android.os.Build.VERSION.SDK_INT >= 14) {
  17. builder = new AlertDialog.Builder(new ContextThemeWrapper(
  18. MyActivity.this,
  19. android.R.style.Theme_DeviceDefault_Light_Dialog));
  20. } else {
  21. builder = new Builder(MyActivity.this);
  22. }
  23.  
  24. if (title != null) {
  25. builder.setTitle(title);
  26. }
  27. if (message != null) {
  28. builder.setMessage(message);
  29. }
  30.  
  31. if (positiveButton != null) {
  32. builder.setPositiveButton(positiveButton, onClickPositive);
  33. }
  34. if (negativeButton != null) {
  35. builder.setNegativeButton(negativeButton, onCLickNegative);
  36. }
  37. builder.setCancelable(cancelable);
  38.  
  39. dialog = builder.show();
  40. colorizeDialog(dialog);
  41. }
  42. });
  43. }
  44. }
  45.  
  46. //theme-xml
  47. <style name="Theme.DeviceDefault.Light.Dialog" parent="Theme.Holo.Light.Dialog" >
  48. <item name="android:windowTitleStyle">@android:style/DialogWindowTitle.DeviceDefault.Light</item>
  49. <item name="android:windowAnimationStyle">@android:style/Animation.DeviceDefault.Dialog</item>
  50.  
  51. <item name="android:buttonBarStyle">@android:style/DeviceDefault.Light.ButtonBar.AlertDialog</item>
  52. <item name="borderlessButtonStyle">@android:style/Widget.DeviceDefault.Light.Button.Borderless.Small</item>
  53.  
  54. <item name="textAppearance">@android:style/TextAppearance.DeviceDefault.Light</item>
  55. <item name="textAppearanceInverse">@android:style/TextAppearance.DeviceDefault.Light.Inverse</item>
  56. </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement