Android中自定义Dialog


/**
 * 帮助提示框类
 *          提供弹出帮助信息
 */
public class DanganDialog extends Dialog {

    private TextView textView;
   
    private Context context;

    private DanganDialog(@NonNull Context context) {
        super(context);
        context = getContext();
        this.setContentView(R.layout.dangan);//绑定试图(自己写的xml)
     
        textView = this.findViewById(R.id.textView);

    }

    /**
     * 静态显示类:直接调用即可弹出帮助提示:可以设置消失后的监听器
     * @param context
     * @param listener
     */
    public static void show(Context context, OnDismissListener listener){
        if (context == null){
            return;
        }
        DanganDialog helpDialog =  new DanganDialog(context);
        Window window = helpDialog.getWindow();
        if (window != null){
            window.setAttributes(new WindowManager.LayoutParams());
            helpDialog.show();
            helpDialog.setOnDismissListener(listener);
        }
    }

}

当点击某个按钮时,实现弹出Dialog

 DanganDialog.show(this);

猜你喜欢

转载自blog.csdn.net/weixin_46409629/article/details/129697058