zoukankan      html  css  js  c++  java
  • Android如何自定义dialog

    package com.example.aqua.myapplicationtesthttp;

    import android.app.Dialog;
    import android.content.Context;
    import android.content.DialogInterface;
    import android.text.Layout;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.view.Window;
    import android.view.WindowManager;
    import android.widget.Button;
    import android.widget.LinearLayout;
    import android.widget.TextView;

    /**
    * Created by Aqua on 2015/12/15.
    */
    public class PopUpView extends Dialog {

    public PopUpView(Context context) {
    super(context);
    }

    public PopUpView(Context context, int theme) {
    super(context, theme);
    }


    public static class Builder {
    private Context context;
    private String message;
    private String positiveButtonText;
    private DialogInterface.OnClickListener positiveButtonClickListener;

    public Builder(Context context) {
    this.context = context;
    }

    public Builder setMessage(String message) {
    this.message = message;
    return this;
    }

    public Builder setPositiveButton(int positiveButtonText,
    DialogInterface.OnClickListener listener) {
    this.positiveButtonText = (String) context
    .getText(positiveButtonText);
    this.positiveButtonClickListener = listener;
    return this;
    }

    public Builder setPositiveButton(DialogInterface.OnClickListener listener) {
    this.positiveButtonClickListener = listener;
    return this;
    }

    public PopUpView create() {
    LayoutInflater inflater = (LayoutInflater) context
    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    // instantiate the dialog with the custom Theme
    final PopUpView dialog = new PopUpView(context);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    View layout = inflater.inflate(R.layout.popupview, null);
    // ViewGroup.LayoutParams pp = new ViewGroup.LayoutParams(500,300);//使用此处修改Dialog的宽和高
    ViewGroup.LayoutParams pp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    dialog.addContentView(layout, pp);
    dialog.setCancelable(false);//使dialog不会消失

    //修改Dialog的宽度和高度
    Window window = dialog.getWindow();
    WindowManager.LayoutParams lp = window.getAttributes();
    lp.alpha = 0.7f;
    lp.width = 500;
    lp.height = 300;
    window.setAttributes(lp);

    // set the confirm button
    if (positiveButtonClickListener != null) {
    ((Button) layout.findViewById(R.id.btn))
    .setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
    positiveButtonClickListener.onClick(dialog,
    DialogInterface.BUTTON_POSITIVE);
    }
    });
    }

    // set the content message
    if (message != null) {
    ((TextView) layout.findViewById(R.id.msg)).setText(message);
    }

    // dialog.setContentView(layout);切忌不需要这一句
    return dialog;
    }




    }
    }
  • 相关阅读:
    [转]Convolution Neural Network (CNN) 原理与实现
    [转]深度学习CNN研究反向
    [转]一张图看懂:Google AlphaGo的原理、弱点
    [转]前馈型神经网络与反馈型神经网络的区别
    [转]认知机和神经认知机
    [转]技术向:一文读懂卷积神经网络CNN
    PHP 日期格式化 参数参考
    PHP MAIL DEMO(程序代码直接发送邮件)
    PHP上传文件DEMO
    PDO事务管理DEMO
  • 原文地址:https://www.cnblogs.com/ISAN-Liu/p/5055684.html
Copyright © 2011-2022 走看看