的Android AlertDialog圆角:矩形看到下面的角落
问题描述:
我想Dialog
圆角,但是当Dialog
看到有下方的矩形见过下面的角落,像这样:的Android AlertDialog圆角:矩形看到下面的角落
我建立使用自定义DialogFragment
的dialog
:
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()
方法