/** * @category 弹出提示框 * @param c:false不显示取消按钮,true为显示 * */ @SuppressWarnings("deprecation") public static void showHD(Activity mActivity, String text, boolean c) { final Dialog dialog = new Dialog(mActivity, R.style.Dialog); View view = LayoutInflater.from(mActivity).inflate(R.layout.dialog_hiti, null); Button btn_cancle = (Button) view.findViewById(R.id.btn_cancle); Button btn_confrim = (Button) view.findViewById(R.id.btn_confrim); TextView tv_hint = (TextView) view.findViewById(R.id.tv_msg); tv_hint.setText(text); dialog.setCancelable(false); dialog.setCanceledOnTouchOutside(false); dialog.setContentView(view); dialog.show(); WindowManager windowManager = mActivity.getWindowManager(); Display display = windowManager.getDefaultDisplay(); WindowManager.LayoutParams lp = dialog.getWindow().getAttributes(); lp.width = (int) (display.getWidth()); dialog.getWindow().setAttributes(lp); Window dialogWindow = dialog.getWindow(); if (c) { btn_cancle.setVisibility(View.GONE); } else { btn_cancle.setVisibility(View.VISIBLE); } dialogWindow.setGravity(Gravity.CENTER); btn_confrim.requestFocus(); btn_cancle.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { dialog.dismiss(); } }); btn_confrim.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { dialog.dismiss(); } }); }
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@color/white" android:orientation="vertical" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="20dp" android:text="提示" android:textColor="@color/btn_red" android:textSize="18sp" /> <View android:layout_width="fill_parent" android:layout_height="1px" android:background="@color/btn_blue" /> <TextView android:id="@+id/tv_msg" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="15dp" android:textColor="@color/black" android:textSize="18sp" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="10dp" android:orientation="horizontal" > <Button android:id="@+id/btn_cancle" android:layout_width="0dp" android:layout_height="40dp" android:layout_margin="20dp" android:layout_weight="1" android:background="@color/btn_yellow" android:text="取消" android:textColor="@color/white" /> <Button android:id="@+id/btn_confrim" android:layout_width="0dp" android:layout_height="40dp" android:layout_margin="20dp" android:layout_weight="1" android:background="@color/btn_red" android:text="确定" android:textColor="@color/white" /> </LinearLayout> </LinearLayout>