圆角的Dialog

这是项目中用到的圆角的dialog,记录于此。


import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

/**
 * Created by LY on 2016/5/18.
 * 圆角的dialog
 */
public class RoundCornerDialog extends Dialog {

    private static int default_width = 160; //默认宽度
    private static int default_height = 120;//默认高度

    public RoundCornerDialog(Context context, View layout, int style) {
        this(context, default_width, default_height, layout, style);
    }


    public RoundCornerDialog(Context context, int width, int height, View layout, int style) {
        super(context, style);
        setContentView(layout);
        Window window = getWindow();
        WindowManager.LayoutParams params = window.getAttributes();
        params.gravity = Gravity.CENTER;
        window.setAttributes(params);
    }

    //圆角的dialog样式
//    


}

项目中使用:

  /**
     * 展示加载中的dialog
     */
     private RoundCornerDialog roundCornerDialog_loading;
    private void showLoadingDialog() {
        View view = View.inflate(context, R.layout.dialog_loading, null);
        roundCornerDialog_loading = new RoundCornerDialog(context, 0, 0, view, R.style.RoundCornerDialog);
        roundCornerDialog_loading.show();
        roundCornerDialog_loading.setCanceledOnTouchOutside(false);// 设置点击屏幕Dialog不消失
        roundCornerDialog_loading.setOnKeyListener(keylistener);//设置点击返回键Dialog消失,并关闭此Activity

        ImageView iv_loading = (ImageView) view.findViewById(R.id.iv_loading);
        Glide.with(context)
                .load(R.drawable.loading1)
                .asGif()
                .into(iv_loading);
    }

    DialogInterface.OnKeyListener keylistener = new DialogInterface.OnKeyListener() {
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
                if (roundCornerDialog_loading != null) {
                    roundCornerDialog_loading.dismiss();
                    backPage();
                }
                return true;
            } else {
                return false;
            }
        }
    };

布局文件:






    

        
    




    
    
    
    
    

    
    


你可能感兴趣的:(AndroidUtil汇总)