PopupWindow的使用及背景变暗设置

//弹出PopupWindow的封装方法
public void showpop()
{
	PopupWindow pop=new PopupWindow(width-40,LayoutParams.MATCH_PARENT);
	pop.setContentView(view_pop);
         //点击空白区关闭
          //p.setFocusable(true);
	pop.setBackgroundDrawable(new ColorDrawable(0));
	// 设置SelectPicPopupWindow弹出窗体动画效果
	pop.setAnimationStyle(android.R.style.Animation);
	//相对父(Activity)view的位置
                    pop.showAtLocation(getActivity().findViewById(R.id.framelayout), Gravity.BOTTOM, 0, 0);

                    //设置透明度

                  backgroundAlpha(0.6f);

}

/**

 * 设置添加屏幕的背景透明度

* @param bgAlpha

 */

public void backgroundAlpha(float bgAlpha)

{

 WindowManager.LayoutParams lp =getActivity().getWindow().getAttributes();

lp.alpha = bgAlpha; //0.0-1.0

 getActivity().getWindow().setAttributes(lp);

}

你可能感兴趣的:(安卓,PopupW)