实现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);
具体参数查看源码
实现PopupWindow透明效果
本文介绍了一种在Android应用中实现PopupWindow透明效果的方法。通过自定义一个带有圆角和透明背景的形状资源文件,并将其设置为PopupWindow的背景,可以达到美观且实用的透明效果。文中还提供了具体的代码实现步骤。
863

被折叠的 条评论
为什么被折叠?



