从问题Issue dismissing popup window我学习了如何隐藏popupWindow
(在此之前,以下代码中的popupWindow.dismiss();
无效)。
private void initFAB(){
fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
boolean showPopupWindow = false;
public void onClick(View view) {
LayoutInflater layoutInflater = (LayoutInflater) getBaseContext()
.getSystemService(LAYOUT_INFLATER_SERVICE);
View popupWindowContent = layoutInflater.inflate(R.layout.popup_window_content, null);
final PopupWindow popupWindow = new PopupWindow(popupWindowContent,
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
popupWindow.setOutsideTouchable(true);
if (!showPopupWindow){
rotateFabForward();
View.OnClickListener onClickListener = new View.OnClickListener() {
public void onClick(View view) {
//...
}
};
// ...
popupWindow.showAtLocation(fab, Gravity.END | Gravity.BOTTOM, 50, 400);
showPopupWindow = true;
}
else{
rotateFabBackward();
popupWindow.dismiss();
showPopupWindow = false;
}
}
});
}
现在,当我在popupWindow
外面点击它消失时,FloatingActionButton
不会向后旋转(当+
被隐藏并旋转时,它会有popupWindow
图标当×
可见时,degress和图标变为popupWindow
。
任何允许在popupWindow
外注册触摸并执行rotateFabBackward()
的侦听器?
P上。 S.另外,感谢关于FAB轮换的this问题的答案。
答案 0 :(得分:1)
你应该像那样添加onDismiss监听器
popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
@Override
public void onDismiss() {
rotateFabBackward();
showPopupWindow = false;
// end may TODO anything else
}
});