前言
之前有写,好像也写过笔记,但不知放哪了。
PS: 这里只是简单记录,谢谢
好记性不如烂笔头
正文
直接上之前我写的代码(哈哈哈,将就一下吧),理论咱们不讲,自个百度。
dialog_theme
    <!-- dalog style -->
    <style name="dialog_theme" 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.5</item>
    </style>
tips_dialog_layout.xml
这里只是大概的框架,具体需求自己增加。
tips_dialog_bg 对话框的背景 tips_dialog_width 定义tips_dialog_bg的宽 tips_dialog_height 定义tips_dialog_bg的高
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="@dimen/tips_dialog_width"
    android:layout_height="@dimen/tips_dialog_height"
    android:background="@drawable/tips_dialog_bg" >
</RelativeLayout>
TipsDialog.java
public class TipsDialog {
    private static Dialog mDialog = null;
    private static View view = null;
    public static void show(Context context) {
        if (null == context) {
            context = MyApp.getContext(); //Application中定义接口
        }
        if (null == mDialog) {
            mDialog = new Dialog(context, R.style.dialog_theme);
        }
        view = LayoutInflater.from(context).inflate(R.layout.tips_dialog_layout, null);
        RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
                context.getResources().getDimensionPixelSize(R.dimen.tips_dialog_width),
                context.getResources().getDimensionPixelSize(R.dimen.tips_dialog_height));
        mDialog.setContentView(view, lp);
        mDialog.setCanceledOnTouchOutside(false);
        mDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
        if (!mDialog.isShowing()) {
            mDialog.show();
        }
        return;
    }
    public static void hide() {
        if (null != mDialog) {
            mDialog.hide();
            mDialog = null;
        }
        return;
    }
}
参考文章
这是看之前写的代码誊上的,具体引用谁家的我就忘了。感谢
