首页 > 代码库 > popupwindow popupmenu
popupwindow popupmenu
private void iniPopupWindow() {
LayoutInflater inflater = (LayoutInflater) this .getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.task_detail_popupwindow, null);
pwMyPopWindow = new PopupWindow(layout);
pwMyPopWindow.setFocusable(true);// 加上这个popupwindow中的ListView才可以接收点击事件
lvPopupList.setAdapter();
// 控制popupwindow点击屏幕其他地方消失
pwMyPopWindow.setBackgroundDrawable(this.getResources().getDrawable(
R.drawable.bg_popupwindow));// 设置背景图片,不能在布局中设置,要通过代码来设置
pwMyPopWindow.setOutsideTouchable(true);// 触摸popupwindow外部,popupwindow消失。这个要求你的popupwindow要有背景图片才可以成功,如上
// 更多操作按钮
ibOperationMore = (ImageButton) findViewById(R.id.ib_operate_more);
ibOperationMore.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (pwMyPopWindow.isShowing()) {
pwMyPopWindow.dismiss();// 关闭
} else {
pwMyPopWindow.showAsDropDown(ibOperationMore);// 显示
}
}
});
popupwindow popupmenu