经常安卓开发要用苹果风格的东西,比如dialog

直接上代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
   | public class SimpleDialog extends AlertDialog {     private String title;     private String left;     private String right;     private View.OnClickListener listener;
      public SimpleDialog(@NonNull Context context,String title,String left,String right, View.OnClickListener listener) {         super(context);         this.title = title;         this.left = left;         this.right = right;         this.listener = listener;     }
      @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.dialog_simple);
          Window window = getWindow();         WindowManager.LayoutParams lp = window.getAttributes();         lp.width = SizeUtils.dp2px(250F);         window.setAttributes(lp);
 
          window.setBackgroundDrawableResource(android.R.color.transparent);
          TextView tvTitle = (TextView) findViewById(R.id.tv_title);         TextView tvLeft = (TextView) findViewById(R.id.tv_left);         TextView tvRight = (TextView) findViewById(R.id.tv_right);         tvTitle.setText(title);         tvLeft.setText(left);         tvRight.setText(right);         tvLeft.setOnClickListener(listener);         tvRight.setOnClickListener(listener);     } }
  | 
 
在dialog的布局文件中,宽度最好用match_parent和weight=1,高度可以写固定值。然后在window里设置具体宽度,高度不设置。