@Override
public
void
onClick(View v) {
/** MenuItem dismiss */
mPopWindow.dismiss();
/**
* 自定义PopupWindow模拟多功能Toast
*/
View popToastView = mLayoutInflater.inflate(
R.layout.dialog_toast,
null
);
mPopToast =
new
PopupWindow(popToastView,
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT,
true
);
mPopToast.setBackgroundDrawable(
new
ColorDrawable(
Color.TRANSPARENT));
mPopWindow.setOutsideTouchable(
true
);
mPopToast
.setAnimationStyle(android.R.style.Animation_Dialog);
mPopToast.showAtLocation(v,
Gravity.BOTTOM | Gravity.CENTER,
0
,
300
);
/**
* 用PopupWindow模拟Toast,里面的TextView的点击事件。
* 因为Toast不获取焦点,所以View的事件无法处理。
* 而PopupWindow解决了这个焦点问题。
*/
TextView dialogContent = (TextView) popToastView
.findViewById(R.id.dialog_content);
dialogContent.setOnClickListener(
new
OnClickListener() {
@Override
public
void
onClick(View v) {
if
(mPopToast !=
null
&& mPopToast.isShowing()) {
mPopToast.dismiss();
/** 再次显示自定义Toast, 这次是从PopupWindow里面的TextView触发的 */
View toastViewAgain = mLayoutInflater.inflate(
R.layout.dialog_toast,
null
);
showToast(toastViewAgain);
}
}
});
/** 显示自定义Toast */
View toastView = mLayoutInflater.inflate(
R.layout.dialog_toast,
null
);
showToast(toastView);
}