1 背景置灰:
popupWindow = new PopupWindow(menuView, LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT, true);
第二三个参数必须是LayoutParams.FILL_PARENT,这样才能填充整个屏幕,达到背景置灰的目的。
2 popupwindow的边框,圆角背景。downbutton_corne.xml
<shape xmlns:android&#61;"http://schemas.android.com/apk/res/android"
android:shape&#61;"rectangle">
<gradient android:startColor&#61;"#c0000000" android:endColor&#61;"#c0000000"
android:angle&#61;"90" />
<stroke android:dashWidth&#61;"2dp" android:dashGap&#61;"2dp"
android:width&#61;"2dp" android:color&#61;"#FF00ff00">stroke>
<corners android:bottomRightRadius&#61;"5dp"
android:bottomLeftRadius&#61;"5dp" android:topLeftRadius&#61;"5dp"
android:topRightRadius&#61;"5dp" />
shape>
3 淡入淡出动画
popupWindow.setAnimationStyle(R.style.PopupAnimation);
这条代码是设置style的&#xff0c;动画文件就是在style文件里面引入的。下面是淡入的动画&#xff0c;动画教程网上也很多。淡出的动画就这些参数值交换位置就是了。android:duration这个是持续时间.
<set xmlns:android&#61;"http://schemas.android.com/apk/res/android">
<scale android:fromXScale&#61;"0.6" android:toXScale&#61;"1.0"
android:fromYScale&#61;"0.6" android:toYScale&#61;"1.0" android:pivotX&#61;"50%"
android:pivotY&#61;"50%" android:duration&#61;"5000" />
<alpha android:interpolator&#61;"&#64;android:anim/decelerate_interpolator"
android:fromAlpha&#61;"0.0" android:toAlpha&#61;"1.0" android:duration&#61;"5000" />
set>
4 响应返回键
new
PopupWindow(view, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
true
);
关键在于最后一个参数&#xff0c;ADK 给出的提示是 Focusable&#xff0c;顾名思义就是该 PW 的 Focusable 属性&#xff0c;让它能够接受焦点。
popupWindow.setBackgroundDrawable(
new
BitmapDrawable());
// 响应返回键必须加上这句
在popupwindow的view加上 setOnKeyListener&#xff0c;就能解决。