2013-02-28 76 views
2

我想Dialog圓角,但是當Dialog看到有下方的矩形見過下面的角落,像這樣:的Android AlertDialog圓角:矩形看到下面的角落

enter image description here

我建立使用自定義DialogFragmentdialog

public class MyDialogFragment extends DialogFragment{ 
@Override 
public Dialog onCreateDialog(Bundle savedInstanceState) { 
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); 
    LayoutInflater inflater = getActivity().getLayoutInflater(); 

    builder.setView(inflater.inflate(R.layout.playdialog, null)); 
    return builder.create(); 
} 
} 

對話框佈局(playdialog)具有以下可繪製背景:

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > 

    <solid 
     android:color="#AAAAAAAA" /> 

    <stroke 
     android:width="2dp" 
     android:color="#FF000000" /> 

    <corners android:radius="20dp" /> 
</shape> 

正如我所說的,我設置繪製背景:

android:background="@drawable/dialog_background" 

我不希望這樣的矩形待觀察。我該怎麼做??

this後用戶有同樣的問題。我試圖使用爲他工作的解決方案,但它並不適合我。我修改了DialogFragment這樣的:

public Dialog onCreateDialog(Bundle savedInstanceState) { 
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); 
    LayoutInflater inflater = getActivity().getLayoutInflater(); 

    builder.setView(inflater.inflate(R.layout.playdialog, null)); 
    Dialog d = builder.create(); 
    d.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); 

    return d; 
} 

結果是完全一樣的。我怎樣才能刪除矩形?

謝謝!

回答

2

請儘量把DialogFragment的樣式設置爲Theme_Translucent.

setStyle(STYLE_NO_FRAME, android.R.style.Theme_Translucent); 

這對我的作品。

0

試試這個:

customDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
4

我感到很震驚,我發生了同樣的問題,解決的辦法是也有點怪異。創建您自己的自定義繪圖,例如見下文。

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle" > 

    <solid android:color="@color/text_highlight" /> 

    <stroke 
     android:width="5dp" 
     android:color="@color/text_highlight" /> 

    <corners android:radius="12dp" /> 

    <stroke 
     android:width="1dp" 
     android:color="@android:color/transparent" /> 

</shape> 

添加以下行到您的對話框:

dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 

// This is line that does all the magic 
dialog.getWindow().setBackgroundDrawableResource(        
R.drawable.dialog_rounded); 
0

我設置一個透明背景,在代碼對話框。 試試這個:

@Override 
public void onStart() { 
    // TODO Auto-generated method stub 
    super.onStart(); 
    getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(0x00ffffff)); 
} 
0

添加
getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

您MyDialogFragment的onCreateView()方法