android - Android 中不显示弹出窗口的背景

标签 android popup

我是一名新的 Android 开发人员,正在尝试编写一本简单的通讯录。当我选择删除按钮时,它必须在弹出窗口中要求确认。但是弹出窗口没有背景。在我的代码中,我在同一父 Activity 的监听器中编写了弹出窗口。

enter image description here

    protected void delPopup() {
        // TODO Auto-generated method stub
       LayoutInflater inflater = (LayoutInflater) DisplayContact.this
               .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
       View layout = inflater.inflate(R.layout.sure,(ViewGroup) findViewById(R.id.popup_element));
       yes_btn = (Button) layout.findViewById(R.id.buttonYes);
        no_btn = (Button) layout.findViewById(R.id.buttonNo);
       pw = new PopupWindow(layout, 300, 470, true);
       pw.showAtLocation(layout, Gravity.CENTER, 0, 0);

       prepareListeners();
       buttonClick();
       mOpenHelper = new DatabaseHelper(this);

    };

xml文件是这样的

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/popup_element"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

和一个 TextView ,2个按钮 有人可以指导我有什么问题吗?

最佳答案

弹出窗口的背景默认是透明的。您必须为弹出窗口设置背景。

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/popup_element"
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    android:background="#000000"

    android:orientation="vertical" >

关于android - Android 中不显示弹出窗口的背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9613572/

相关文章:

java - OpenCV 特征检测器

java - PopupWindow 与 ActionBar 重叠

java - BitmapFont 类没有 getBound(String) 方法

带有游标的Android列表设计问题

Android - 空闲条件数据丢失

jquery - jQuery 中的弹出窗口

asp.net - 弹出窗口,如何在IE8中隐藏地址栏

javascript - 如何使用链接而不是按钮打开模式弹出窗口

javascript - 这些不同样式的 "pop up"框的正确术语是什么以及如何实现它们?

php - Openssl RSA加密-解密