【问题标题】:Darken Background after Popup window opened android弹出窗口打开后使背景变暗android
【发布时间】: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>

我现在该怎么办?

【问题讨论】:

标签: android android-studio


【解决方案1】:

你可以试试这个

替换

popup.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));

在你的代码中加入这个

popup.setBackgroundDrawable(new ColorDrawable(Color.BLACK));

您可以根据需要更改任何背景。

【讨论】:

  • 是在你的 color.java 文件中这样定义的黑色请检查
  • @ColorInt public static final int BLACK = 0xFF000000;
  • 如果没有,那么你可以这样做,我已经测试过了。
  • 还有另一种使用警告对话框打开布局的方法我也有代码
  • 使用android:background="@null"
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-02
  • 2014-12-26
  • 2016-05-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多