1.主要代码:
声明:
private View shareView; private PopupWindow pop;
在onCreate方法里:
// 引入窗口配置文件
shareView = LayoutInflater.from(this).inflate(
R.layout.jyx_activity_share, null);
// 创建PopupWindow对象
pop = new PopupWindow(shareView, LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT, false);
// 需要设置一下此参数,点击外边可消失
pop.setBackgroundDrawable(new ColorDrawable());
// 设置点击窗口外边窗口消失
pop.setOutsideTouchable(true);
pop.setAnimationStyle(R.style.AnimationPreview);
// 设置此参数获得焦点,否则无法点击
pop.setFocusable(true);
pop.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss() {
ShareSDK.stopSDK(ProductActivity.this);
}
});
在onClick事件里:(一个是分享的按钮,一个是弹框里的取消按钮)
case R.id.share:
if (pop != null && !pop.isShowing()) {
pop.showAtLocation(view.getRootView(), Gravity.BOTTOM, 0, 0);
}
break;
case R.id.btn_cancel:
if (pop != null && pop.isShowing()) {
pop.dismiss();
}
break;
Android的PopupWindow弹窗(以常见的分享界面为例)
原文:http://blog.csdn.net/lyy1104/article/details/39054237