SingleButtonDialog.java 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package com.yyrh.ui.dialog;
  2. import android.app.Dialog;
  3. import android.content.Context;
  4. import android.content.DialogInterface;
  5. import android.view.LayoutInflater;
  6. import android.view.View;
  7. import android.view.ViewGroup;
  8. import android.widget.TextView;
  9. import com.yyrh.utils.ResourceUtil;
  10. public class SingleButtonDialog extends Dialog {
  11. private static TextView bt_exit_game,content;
  12. private static SingleButtonDialog dialog;
  13. public SingleButtonDialog(Context context, int theme) {
  14. super(context, theme);
  15. }
  16. public static class Builder{
  17. private Context context;
  18. private OnClickListener positiveButtonClickListener;
  19. public Builder(Context context){ this.context = context;}
  20. public Builder setPositiveButton(OnClickListener listener){
  21. this.positiveButtonClickListener = listener;
  22. return this;
  23. }
  24. public void dialogDismiss(){dialog.dismiss();}
  25. public SingleButtonDialog Create(String msg){
  26. {
  27. LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  28. dialog = new SingleButtonDialog(context,ResourceUtil.getStyleId(context,"qj_base_dialog"));
  29. View layout;
  30. layout = inflater.inflate(ResourceUtil.getLayoutId(context, "qj_ios_style_dialog"),null);
  31. dialog.addContentView(layout,new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
  32. bt_exit_game =(TextView) dialog.findViewById(ResourceUtil.getId(context,
  33. "confirm"));
  34. content =(TextView) dialog.findViewById(ResourceUtil.getId(context,
  35. "content"));
  36. content.setText(msg);
  37. if (bt_exit_game!=null){
  38. bt_exit_game.setOnClickListener(new View.OnClickListener() {
  39. @Override
  40. public void onClick(View view) {
  41. positiveButtonClickListener.onClick(dialog,DialogInterface.BUTTON_POSITIVE);
  42. }
  43. });
  44. }
  45. }
  46. return dialog;
  47. }
  48. }
  49. }