【发布时间】:2016-12-22 07:05:06
【问题描述】:
我想在弹出窗口打开后将背景变暗,并在关闭后恢复所有内容。我搜索了谷歌,也看到了一些教程。但我无法理解这怎么可能。这是我的 Java 代码:
public void displayPopupWindow() {
View layout = getLayoutInflater().inflate(R.layout.popup,null);
final PopupWindow popup = new PopupWindow(this);
popup.setContentView(layout);
popup.setOutsideTouchable(true);
popup.setFocusable(true);
popup.setWidth(400);
popup.setHeight(580);
popup.showAtLocation(layout, Gravity.CENTER, 0, 0);
popup.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
Button button = (Button) layout.findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View layout) {
popup.dismiss();
}
});
}
这是我的弹出 xml 代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/colorPrimary"
android:id="@+id/popup"
>
Various views and button
</RelativeLayout>
我现在该怎么办?
【问题讨论】:
-
我不明白
-
我已经试过了。但这对我不起作用