在工作遇到使用popwindow ,本以为挺简单的,写完就交给测试了,没想到在4.4oppo手机上出现 各种问题,
问题1:popwindow 被状态栏 遮盖住了一部分
问题2:点击 Popwindow 外部区域 没有消失掉,我代码里可是加了设置的。
问题3:弹出popwindow后 屏幕背景应该变暗,没有变暗。
问题4:没有弹出动画效果
private void showCustomerServicePop(final String hotline) {
if (customerPopView == null) {
LayoutInflater layoutInflater = (LayoutInflater) this.getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
customerPopView = layoutInflater.inflate(R.layout.pop_customer_service, null);
}
LinearLayout llUdeskService = (LinearLayout) customerPopView.findViewById(R.id.ll_custom_service_udesk);
LinearLayout llPhoneService = (LinearLayout) customerPopView.findViewById(R.id.ll_custom_service_phone); //电话客服
if (customerPopWindow == null) {
customerPopWindow = new PopupWindow(customerPopView,
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
}
//适配4.0-5.0版本的手机
//问题1
ColorDrawable cd = new ColorDrawable(0xb2000000);//70%透明度
customerPopWindow.setBackgroundDrawable(cd);
//问题2
customerPopWindow.setTouchable(true);
customerPopWindow.setOutsideTouchable(true);
//popwindow弹出动画
//问题4
customerPopWindow.setAnimationStyle(R.style.popwinow_anim_style);
//设置各个控件的点击响应
llUdeskService.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//打开udesk
openUdesk();
customerPopWindow.dismiss();
}
});
final String finalHotline = hotline.replaceAll("-", "");
llPhoneService.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MYAlertDialog dialog = new MYAlertDialog(mContext, MYAlertDialog.TYPE_BUTTON_TWO, "客服电话", hotline, "取消", "呼叫") {
@Override
public void clickCallBackRight() {
super.clickCallBackRight();
//拨打客服电话
Intent intent1 = new Intent();
intent1.setAction(Intent.ACTION_CALL);
intent1.setData(Uri.parse("tel:" + finalHotline));
startActivity(intent1);
}
};
dialog.setOnTouchOutsideClose(true);
dialog.show();
customerPopWindow.dismiss();
}
});
//显示PopupWindow
customerPopWindow.showAtLocation(this.getActivity().getWindow().getDecorView(), Gravity.BOTTOM, 0, 0);
//问题3
//屏幕背景变化
final WindowManager.LayoutParams lp = this.getActivity().getWindow().getAttributes();
lp.alpha = 0.7f;
final Window w = this.getActivity().getWindow();
w.setAttributes(lp);
customerPopWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
@Override
public void onDismiss() {
lp.alpha = 1;
w.setAttributes(lp);
}
});
animation
<style name="popwinow_anim_style">
<item name="android:windowEnterAnimation">@anim/popwindow_open</item>
<item name="android:windowExitAnimation">@anim/popwindow_close</item>
</style>
open animation
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="200"
android:fromYDelta="100%"
android:interpolator="@android:anim/decelerate_interpolator"
android:toYDelta="0" />
close animation
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="200"
android:fromXDelta="0"
android:fromYDelta="0"
android:interpolator="@android:anim/decelerate_interpolator"
android:toXDelta="0"
android:toYDelta="100%" />