Android:如何从AlertDialog中删除矩形角?

时间:2013-12-21 08:26:13

标签: android xml

enter image description here

我试过了:

AlertDialog.Builder alertSeverity = new AlertDialog.Builder(getActivity(), android.R.style.Theme_Translucent_NoTitleBar);

但它说, 调用需要API级别11(当前最小值为8):new android.app.AlertDialog.Builder

我也发现了其他方法,比如定义形状

<shape android:shape="rectangle">
    <solid android:color="#FFFFFF" />
    <corners android:topLeftRadius="5dp" android:topRightRadius="5dp" />
    <stroke android:color="#FFFFFF" android:width="1dp" />
</shape>

但我不知道我的角落正在制作什么。是的,我可以做出假设。但我只想问是否有任何简单的方法可以做到这一点?

2 个答案:

答案 0 :(得分:0)

创建以下样式将其设置为对话框背景

<style name="CustomDialogTheme" parent="@android:style/Theme.Dialog">
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:windowIsFloating">false</item>
        <item name="android:windowNoTitle">true</item>
</style>

例如:

AlertDialog.Builder alertSeverity = new AlertDialog.Builder(getActivity(), R.style.CustomDialogTheme);

这里windowBackground是从对话框中删除边框的键。

修改

试试这个:

AlertDialog.Builder alertSeverity =new AlertDialog.Builder(
  new ContextThemeWrapper(getActivity(), R.style.CustomDialogTheme));

答案 1 :(得分:0)

得到了解决方案..

final Dialog dialog = new Dialog(context, R.style.CustomDialogTheme);
dialog.setContentView(R.layout.exitview);

Button yes_button = (Button) dialog.findViewById(R.id.yes);
yes_button.setOnClickListener(this);

Button no_button = (Button) dialog.findViewById(R.id.no);
no_button.setOnClickListener(this);

dialog.show();

风格,与上述相同,

<style name="CustomDialogTheme" parent="@android:style/Theme.Dialog">
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowIsFloating">false</item>
    <item name="android:windowNoTitle">true</item>
</style>