簡體   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