2011-02-17 54 views
4

我創建了一個具有圓角的背景圖像的自定義對話框。我刪除使用自定義樣式的白色邊框,但是如果同樣大小的黑色矩形背後我的形象,它的顯示,如下圖所示(對話框的背景圖像是棕色的):問題與Android中的透明背景圖像

enter image description here

如何保持圖像的透明背景與圓角?


佈局我的對話框:

<style 
name="Theme_Dialog_Translucent" 
parent="android:Theme.Dialog"> 
<item name="android:windowBackground">@null</item> 
</style> 

我CustomDialog類是:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/confirmation" 
android:orientation="vertical" 
android:background="@drawable/dialog_background" 
android:layout_width="279dp" 
android:layout_height="130dp" 
> 
... 

我通過應用以下樣式到我的對話框中刪除的白色邊框

public class CustomDialog extends Dialog implements OnClickListener { 
Button okButton; 

public CustomDialog(Context context) { 
    // Custom style to remove dialog border - corners black though :(
    super(context, R.style.Theme_Dialog_Translucent); 
    // 'Window.FEATURE_NO_TITLE' - Used to hide the title 
    requestWindowFeature(Window.FEATURE_NO_TITLE);  
    setContentView(R.layout.custom_dialog); 
    okButton = (Button) findViewById(R.id.button_ok); 
    okButton.setOnClickListener(this); 
} 

... 

} 

回答

6

問題是在windowBackground屬性 使用該

<item name="android:windowBackground">#00000000</item> 

這將使窗口背景透明的嘗試。

我希望能夠解決問題

+2

是的,它確實解決了問題!謝謝。我不能直接設置十六進制值,我必須將它設置爲 @ color/transparent,並創建一個color.xml文件,其中包含 #00000000。 – jul 2011-02-18 13:47:40