2011-11-19 59 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