【发布时间】:2018-03-26 03:24:01
【问题描述】:
我正在尝试制作一个弹出窗口,其中将包含文本字段和信息以询问用户,但我想知道如何制作它以便用户可以通过单击主要片段/活动所在的弹出窗口外部来关闭它是。
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.tabstudygroups, container, false);
listview = (ListView) rootView.findViewById(R.id.clist2);
addCourseButton = (Button) rootView.findViewById(R.id.caddcoursebutton);
// do stuff here
addCourseButton.setOnClickListener(this);
return rootView;
}
@Override
public void onClick(View v) {
if(v == addCourseButton) {
View popupView = LayoutInflater.from(getActivity()).inflate(R.layout.popup_layout, null);
final PopupWindow popupWindow = new PopupWindow(popupView, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
// HERE IS WHAT I THOUGHT WOULD MAKE IT BE ABLE TO ENABLE THE OUTSIDE TOUCH
popupWindow.setBackgroundDrawable(new BitmapDrawable());
popupWindow.setOutsideTouchable(true);
Button btn = (Button) popupView.findViewById(R.id.button);
popupWindow.showAsDropDown(popupView, 0, 0);
}
}
}
【问题讨论】:
标签: android android-layout android-fragments android-popupwindow