PopupWindow,可以在当前屏幕的上层的显示一个弹窗,这个弹出框是悬浮在当前activity之上的,可以指定弹窗的位置以及背景色等特性,可以使用任意布局的View作为其内容。
private void showPopupWindow(View view) {
LayoutInflater mLayoutInflater = (LayoutInflater)getSystemService(LayoutInflaterService);
View contentView= mLayoutInflater.Inflate(R.layout.pop_window,
null);
Button button = (Button) contentView.findViewById(R.id.button1);
button.setOnClickListener(
new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(
this,
"button is pressed",
Toast.LENGTH_SHORT).show();
}
});
final PopupWindow popupWindow =
new PopupWindow(contentView,
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
popupWindow.setTouchable(
true);
popupWindow.focusable =
true;
popupWindow.OutsideTouchable =
true;
ColorDrawable dw =
new ColorDrawable(Color.Transparent);
popupWindow.SetBackgroundDrawable(dw);
popupWindow.ShowAtLocation(view, GravityFlags.Center,
0,
0);
popupWindow.Update();
view.FocusableInTouchMode =
true;
popupWindow.setTouchInterceptor(
new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Log.i(
"mengdd",
"onTouch : ");
return false;
}
});
}
void loginbtn_Click(
object sender, EventArgs e)
{
if(popupWindow !=
null && popupWindow.IsShowing)
{
popupWindow.dismiss();
return;
}
showPopupWindow(Resource.Layout.layout_main);
}
转载请注明原文地址: https://ju.6miu.com/read-1299934.html