Android PopupWindow增加半透明蒙层增加半透明蒙层
本文实例为大家分享了Android PopupWindow增加半透明蒙层的具体代码,供大家参考,具体内容如下
先看效果图:
实现代码:实现代码:
BasePopupWindowWithMask.class
package com.example.popupwindowwithmask;
import android.content.Context;
import android.graphics.PixelFormat;
import android.graphics.drawable.ColorDrawable;
import android.os.IBinder;
import android.view.KeyEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.PopupWindow;
/**
* Created by kk on 2017/7/22.
*/
public abstract class BasePopupWindowWithMask extends PopupWindow {
protected Context context;
private WindowManager windowManager;
private View maskView;
public BasePopupWindowWithMask(Context context) {
super(context);
this.context = context;
windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
setContentView(initContentView());
setHeight(initHeight());
setWidth(initWidth());
setOutsideTouchable(true);
setFocusable(true);
setTouchable(true);
setBackgroundDrawable(new ColorDrawable());
}
protected abstract View initContentView();
protected abstract int initHeight();
protected abstract int initWidth();
@Override