View contentView;
LayoutInflater mLayoutInflater = LayoutInflater.from(activity);
contentView = mLayoutInflater.inflate(R.layout.layout_popupwindow,
null);
pop = new PopupWindow(contentView,
ViewGroup.LayoutParams.MATCH_PARENT, (int) context.getResources().getDimension(R.dimen.y568));
TextView tvTitle = (TextView) contentView.findViewById(R.id.text);
tvTitle.setText(strTitle);
ListView listView = (ListView) contentView.findViewById(R.id.list);
// 产生背景变暗效果
WindowManager.LayoutParams lp = activity.getWindow()
.getAttributes();
lp.alpha = 0.4f;
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
activity.getWindow().setAttributes(lp);
pop.setTouchable(true);
pop.setFocusable(true);
pop.setBackgroundDrawable(new BitmapDrawable());
pop.setOutsideTouchable(true);
pop.showAtLocation(contentView, Gravity.BOTTOM, 0, 0);
pop.update();
pop.setOnDismissListener(new PopupWindow.OnDismissListener() {
// 在dismiss中恢复透明度
public void onDismiss() {
WindowManager.LayoutParams lp = activity.getWindow()
.getAttributes();
lp.alpha = 1f;
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
activity.getWindow().setAttributes(lp);
}
});
listView.setOnItemClickListener(onItemClickListener);
listView.setAdapter(adapter);
Android PopupWindow背景半透明兼容方案
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 大家想必对PopupWindow不会很陌生吧,我们在开发中经常会遇到要求使其背景半透明的需求,但网上的很多解决方案...
- 关于PopupWindow的使用,网上各种介绍,不胜枚举。我这里记录一下自己写的一个小demo(备忘),背景是半透...
- 常规写法: 以上常规写法在大部分机型上没问题,但是在华为手机上会失效,修改如下: 适配写法:
- 首先定义一个PublishPopWindow 导入注解jar包(部分jar包可不用到) xml布局 定义一个动画工...