Android对话框,删除细长的灰色边框(~2px)周围的对话框

时间:2013-03-20 07:51:40

标签: java android dialog

我需要一种方法来删除Android添加的2px灰色边框到对话框的视图内容。我已尝试在此网站上标记为“正常”的大多数解决方案。期望的最终结果显示在最后一张图片中(一个对话框显示我的视图,没有任何额外的UI元素由android添加)

这是当前代码:

AlertDialog.Builder builder = new Builder(this);
builder.setView(dialogContent); //a view inflated from xml
... 
chooseActionDialog = builder.create();
...
chooseActionDialog.setView(dialogContent, 0, 0, 0, 0); //this removed the padding between grey border & actual content.. this is why i set view twice
chooseActionDialog.show();
...
Drawable d = new ColorDrawable(Color.TRANSPARENT);    
chooseActionDialog.getWindow().setBackgroundDrawable(d);  //this seems to change color of padding area (between grey border & actual content)

注意:带有2个参数(context,themeId)的Builder构造函数按预期工作(仍然有边框和对话框变得难看)

enter image description here

1 个答案:

答案 0 :(得分:3)

在style.xml中的style.xml中创建自己的样式,如下所示

<style name="Theme.Trans" parent="android:Theme.Translucent">
   <item name="android:windowFrame">@null</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowTitleStyle">@null</item>
    <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
    <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
    <item name="android:backgroundDimEnabled">false</item>
    <item name="android:background">@android:color/transparent</item>
</style>

将此样式应用于对话框

final Dialog dialog = new Dialog(UrActivity.this, R.style.Theme_Trans);