them样式
[html] view plain copy <style name="LocaticonDialogStyle" parent="@android:style/Theme.Dialog"> <!-- 背景颜色 --> <item name="android:windowBackground" >@android:color/white</ item> <item name="android:windowFrame" >@null</ item> <!-- 定义对话框显示的动画 --> <item name="android:windowAnimationStyle" >@style/LocationAnimationStyle</ item> <!-- 背后的阴影 --> <item name="android:backgroundDimEnabled" >false</ item> <item name="android:windowIsTranslucent" >true</ item> <!-- 去掉标题 --> <item name="android:windowNoTitle" >true</ item> <!-- 点击外部是否允许取消 --> <item name="android:windowCloseOnTouchOutside" >true</ item> </style > [html] view plain copy 但是我现在要用代码实现,尝试了好多方法,activity的界面外的背景都是黑色的。
Android:backgroundDimEnabled设置false背景是黑色
后面用代码的方式解决了问题
dialog.getWindow().setDimAmount(0f);
解决方案
[java] view plain copy private void showDialog(){ View contentView = View.inflate(this,R.layout.map_postion_item,null); CustomTextView tvJxName = (CustomTextView) contentView.findViewById(R.id.tv_jx_name); CustomTextView tvBranchAddr = (CustomTextView) contentView.findViewById(R.id.tv_branch_address); ImageView iv_call_phone = (ImageView) contentView.findViewById(R.id.iv_call_phone); iv_call_phone.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ToastUtil.show(MapDetailsActivity.this,"拨打电话"); } }); if(mFlag.equals("1")) { tvJxName.setText(mJxSchoolDtl.getSName()); tvBranchAddr.setText(sb != null ? sb.getAddr() : ""); }else { tvJxName.setText(mJxSchoolDtl.getSName()); tvBranchAddr.setText(mJxSchoolDtl.getAddr()); } mDialog = getCommentDialog(contentView); mDialog.getWindow().setDimAmount(0f);//核心代码 解决了无法去除遮罩 mDialog.show(); } public Dialog getCommentDialog(View dialogview){ final Dialog dialog = new Dialog(this, R.style.action_sheet); dialog.setContentView(dialogview); dialog.setCanceledOnTouchOutside(true); Window window = dialog.getWindow(); WindowManager.LayoutParams lp = window.getAttributes(); //window.setBackgroundDrawable(new ColorDrawable());//去除阴影 lp.width = getScreenWidth(); //lp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE; lp.flags = WindowManager.LayoutParams.FLAG_DIM_BEHIND;// 就是这个属性导致不能获取焦点,默认的是FLAG_NOT_FOCUSABLE,故名思义不能获取输入焦点, window.setGravity(Gravity.BOTTOM); return dialog; } 最后献上解决后效果图