实现PopupWindow透明效果,先在drawable定义一个文件:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:startColor="#c0000000" android:endColor="#c0000000"
android:angle="90" />
<!-- <stroke android:dashWidth="2dp" android:dashGap="2dp"
android:width="2dp" android:color="#FF00ff00" /> 描边 -->
<corners android:bottomRightRadius="5dp"
android:bottomLeftRadius="5dp" android:topLeftRadius="5dp"
android:topRightRadius="5dp" /><!--设置圆角-->
</shape>
代码中:
/**
* 初始化弹出等待窗口
*/
private void initPopWindow() {
if (mPopupWindows == null) {
View view = context.getLayoutInflater().inflate(
R.layout.dialog_pop, null);
mPopupWindows = new PopupWindow(view, 120, 100);
((TextView) view.findViewById(R.id.message)).setText(mLoadingMsg);
// mPopupWindows.setBackgroundDrawable(new BitmapDrawable());
}
if (mPopupWindows.isShowing()) {
mPopupWindows.dismiss();
}
}
最后:
mPopupWindows.showAtLocation(context.findViewById(currentId),
Gravity.CENTER, 0, 0);
具体参数查看源码