2012-03-08 92 views
1

我是一名嘗試編寫簡單通訊錄的新的android開發人員。當我選擇刪除按鈕時,它必須要求在彈出窗口中進行確認。但沒有彈出窗口的背景。在我的代碼中,我在同一個父活動中的監聽器中編寫了彈出窗口。彈出窗口的背景不顯示在Android中

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" > 

和文本視圖,2個按鈕 可有人指導我出了什麼問題?

+0

你在哪裏設置背景? – Jayabal 2012-03-08 06:20:16

回答

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" > 
0

嘗試

<?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="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" >