繁体   English   中英

Android对话框,删除细灰色边框(〜2px)环绕对话框

[英]Android dialog, removing the thin grey border (~2px) sorrounding dialog

我需要一种方法来删除Android添加到对话框的视图内容中的2px灰色边框。 我已经尝试过在此站点上标记为“确定”的大多数解决方案。 所需的最终结果显示在最后一张图片中(仅显示我的视图的对话框,未由android添加任何其他UI元素)

这是当前代码:

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构造器按预期完成了工作(仍然使边框和对话框变得难看)

在此处输入图片说明

在values。文件夹中的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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM