的Android AlertDialog圆角:矩形看到下面的角落

问题描述:

我想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; 
} 

结果是完全一样的。我怎样才能删除矩形?

谢谢!

请尽量把DialogFragment的样式设置为Theme_Translucent.

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

这对我的作品。

试试这个:

customDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 

我感到很震惊,我发生了同样的问题,解决的办法是也有点怪异。创建您自己的自定义绘图,例如见下文。

<?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); 

我设置一个透明背景,在代码对话框。 试试这个:

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

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

您MyDialogFragment的onCreateView()方法