gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 22:11:07 25 4
gpt4 key购买 nike

我是一名新的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com