2011-11-19 31 views
4

其實我一直在使用AlertDialog.builder.In此對話框我沒有顯示titile.All工作正常,但有一個黑色邊框出現在dialog.so任何人都可以創建一個自定義對話框中刪除黑色邊框告訴我如何刪除這個黑色boder。代碼和屏幕截圖如下。如何從AlertDialog建設者

代碼Java中:

 AlertDialog.Builder start_dialog = new AlertDialog.Builder(this); 

     Context mContext = getApplicationContext(); 
     LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE); 
     View layout = inflater.inflate(R.layout.custom_dialog2, 
             (ViewGroup) findViewById(R.id.layout_root)); 

     layout.setBackgroundResource(R.drawable.img_layover_welcome_bg); 

     Button btnPositiveError = (Button)layout.findViewById(R.id.btn_error_positive); 
     btnPositiveError.setTypeface(m_facedesc); 

     start_dialog.setView(layout); 

     final AlertDialog alert = start_dialog.create(); 
     alert.show(); 

     btnPositiveError.setOnClickListener(new Button.OnClickListener() 
     { 
      public void onClick(View v) 
      { 
       alert.dismiss(); 
      } 
     }); 

ScrrenShot

enter image description here

+0

我已刪除的背景這樣做:http://stackoverflow.com/questions/8051581 /如何去除的邊界 - 從-對話框。這些問題很可能我合併 – quinestor

回答

0

使用Dialog類,而不是AlertDialog

for eg - Dialog d = new Dialog(context, android.R.style.Theme_Translucent); 

使用setContentView而不是setView。

,並設置其主題爲透明。

+0

我用that..but的是,它使對話框全屏..所以有什麼選擇,以防止它形成全屏 – AndroidDev

6
Without creating a custom background drawable and adding a special style just add 

一行代碼:

dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent); 

更多關於對話框:

Dilaogs

+0

它清除所有的背景,而不僅僅是邊界!無論如何,它適用於我,我使用Layour對話框的顏色。好! –

+0

這個問題的最佳答案,不知道爲什麼人們建議爲這個問題創建一個自定義主題。 –

0

只要你插入

Dialog start_dialog = new Dialog(this); 

,而不是這個

AlertDialog.Builder start_dialog = new AlertDialog.Builder(this); 
0

我也有這個問題。這是更好地使用Dialog而不是AlertDialog。 這是我的解決方案:some_dialog.xml的

Dialog dialog = new Dialog(getActivity(), R.style.Dialog_No_Border); 
dialog.setContentView(R.layout.some_dialog); 

內容

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="250dp" 
     android:layout_height="350dp" 
     android:orientation="vertical" 
     android:background="@drawable/some_dialog_background"> 

     <TextView 
      ... 
     /> 

     <Button 
      ... 
     /> 

    </LinearLayout> 

styles.xml

<style name="Dialog_No_Border" parent="@android:style/Theme.Dialog"> 
    <item name="android:windowIsFloating">true</item> 
    <item name="android:windowBackground">@color/transparent_color</item> 
</style> 

所以,最後我有我的背景定製對話框無國界。

2

更改這行代碼

AlertDialog.Builder start_dialog = new AlertDialog.Builder(this); 

AlertDialog.Builder start_dialog = new AlertDialog.Builder(this).setInverseBackgroundForced(true); 

你將所有設置

+0

你可以設置我的答案爲接受的一個,隊友:) – MohammadReza

+0

它不會讓它透明,只需將顏色更改爲白色 – Salmaan