标签:
/*** Creates an {@link AlertDialog} with the arguments supplied to this* builder.* <p>* Calling this method does not display the dialog. If no additional* processing is needed, {@link #show()} may be called instead to both* create and display the dialog.*/public AlertDialog create() {// Context has already been wrapped with the appropriate theme.final AlertDialog dialog = new AlertDialog(P.mContext, 0, false);P.apply(dialog.mAlert);dialog.setCancelable(P.mCancelable);if (P.mCancelable) {dialog.setCanceledOnTouchOutside(true);}dialog.setOnCancelListener(P.mOnCancelListener);dialog.setOnDismissListener(P.mOnDismissListener);if (P.mOnKeyListener != null) {dialog.setOnKeyListener(P.mOnKeyListener);}return dialog;}
/*** Creates an {@link AlertDialog} with the arguments supplied to this* builder and immediately displays the dialog.* <p>* Calling this method is functionally identical to:* <pre>* AlertDialog dialog = builder.create();* dialog.show();* </pre>*/public AlertDialog show() {final AlertDialog dialog = create();dialog.show();return dialog;}
public static void showSimpleDialog(Context context, String msg, View.OnClickListener listener) {final AlertDialog.Builder builder = new AlertDialog.Builder(context);final AlertDialog dialog = builder.create();LayoutInflater inflater = LayoutInflater.from(context);View view = inflater.inflate(R.layout.dialog_simple_deposit, null);TextView tvConfirm = (TextView) view.findViewById(R.id.tv_confirm);tvConfirm.setOnClickListener(listener);tvConfirm.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {dialog.dismiss();}});TextView tvMsg = (TextView) view.findViewById(R.id.tv_msg);tvMsg.setText(msg);dialog.setView(view);dialog.setCancelable(false);// 返回键不可取消dialog.setView(view, 0, 0, 0, 0);// 可消除部分边框,当不能全部消除dialog.show();}
public static void showSimpleDialog1(Context context, String msg) {final Dialog dialog =new Dialog(context, R.style.dialog);// 可以消除黑色边框LayoutInflater inflater = LayoutInflater.from(context);View view = inflater.inflate(R.layout.dialog_simple_deposit, null);TextView tvConfirm = (TextView) view.findViewById(R.id.tv_confirm);// tvConfirm.setOnClickListener(listener);tvConfirm.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {dialog.dismiss();}});TextView tvMsg = (TextView) view.findViewById(R.id.tv_msg);tvMsg.setText(msg);dialog.setContentView(view);dialog.setCancelable(false);// 返回键不可取消dialog.show();}
<style name="dialog" parent="@android:style/Theme.Dialog"><item name="android:windowFrame">@null</item><item name="android:windowIsFloating">true</item><item name="android:windowIsTranslucent">true</item><item name="android:windowNoTitle">true</item><item name="android:background">@android:color/transparent</item><item name="android:windowBackground">@android:color/transparent</item><item name="android:backgroundDimEnabled">true</item><item name="android:backgroundDimAmount">0.6</item></style>
标签:
原文地址:http://www.cnblogs.com/chenchengzhi/p/5057835.html