2016-03-31 108 views
1

我在我的AlertDialog里面有一个自定义布局,里面有ListView。现在我想删除AlertDialog的黑色背景。删除AlertDialog背景

  AlertDialog.Builder builder = new AlertDialog.Builder(this); 
      LayoutInflater inflater = this.getLayoutInflater(); 
      View dialogView = inflater.inflate(R.layout.rate_card_layout, null); 
      Button close = (Button) dialogView.findViewById(R.id.btnClose); 
      close.setOnClickListener(new OnClickListener() { 

       @Override 
       public void onClick(View arg0) { 

        dialog.dismiss(); 
       } 
      }); 


      ListView lv = (ListView)dialogView.findViewById(R.id.listView1); 
      RateListAdapter rLAdapter = new RateListAdapter(SActivity.this, 
        listItemsArray); 
      lv.setAdapter(rLAdapter); 

      builder.setView(dialogView); 
      final Dialog dialog = builder.create(); 

      dialog.show(); 

我尝试添加

dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); 

如常。但那不起作用。

enter image description here

任何帮助将不胜感激。

+0

组后台 – Pavya

+0

尝试使用阿尔法属性(不知道虽然) – Nilabja

+0

其中黑色背景你指?你能发布你想要的图片吗? – dsharew

回答

1

尝试

private void updateLayoutParams() { 
    Window window = getDialog().getWindow(); 
    WindowManager.LayoutParams params = window.getAttributes(); 
    params.dimAmount = 0.2f; 

    int margin = getResources().getInteger(R.integer.common_margin); 
    DisplayMetrics metrics = new DisplayMetrics(); 
    ((WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getMetrics(metrics); 
    params.width = metrics.widthPixels-margin; 

    window.setAttributes(params); 
    window.setBackgroundDrawableResource(android.R.color.transparent); 
    getDialog().setCanceledOnTouchOutside(false); 

} 
@Override 
public void onConfigurationChanged(Configuration newConfig) { 
    super.onConfigurationChanged(newConfig); 
    Log.d(TAG, "onConfigurationChanged"); 

    updateLayoutParams(); 
} 
0

尝试使用这个自定义您的主题。同时声明AlertDialogCustom IIN风格 AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.AlertDialogCustom));

然后风格像你想:

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <style name="AlertDialogCustom" parent="@android:style/Theme.Dialog"> 
     <item name="android:textColor">#00FF00</item> 
     <item name="android:typeface">monospace</item> 
     <item name="android:textSize">10sp</item> 
     ............. //background etc 
    </style> 
</resources> 
0

尝试这个

添加自定义对话框风格style.xml

<style name="DialogTheme" parent="@android:style/Theme.Dialog"> 
      <item name="android:windowBackground">@android:color/transparent</item>   
    </style> 

在活动

Dialog dialog = new Dialog(this, R.style.DialogTheme); 
在rate_card_layout

OR

AlertDialog.Builder builder=new AlertDialog.Builder(this,R.style.DialogTheme);