营销型网站的作用,赚钱游戏,网站开发的语言有什么软件,建湖做网站的公司问题描述#xff1a; 产品需求弹出的提示框是圆角#xff0c;使用shape 设置圆角背景后#xff0c;弹出的AlertDialog提示框四个角有白色的背景#xff0c;据分析这个背景是 AlertDialog 父组件的背景色。
解决方法#xff1a;
将Dialog的背景设置为透明色#xff0c;代…
问题描述 产品需求弹出的提示框是圆角使用shape 设置圆角背景后弹出的AlertDialog提示框四个角有白色的背景据分析这个背景是 AlertDialog 父组件的背景色。
解决方法
将Dialog的背景设置为透明色代码如下
getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
详细将AlertDialog设置圆角背景方法
1、首先在drawable文件夹下建一个xml文件如ic_background_radius.xml
?xml version1.0 encodingutf-8?
shape xmlns:androidhttp://schemas.android.com/apk/res/androidsolid android:colorcolor/grey_c4c4c4/ //填充色corners android:radius16dp/ //圆角大小
/shape
2、然后在layout文件夹下建一个xml布局文件如dialog_face_compare_layout.xml 。在布局文件的根布局中设置了background属性为drawable/ic_background_radius目的是为了让dialog显示圆角边框。
?xml version1.0 encodingutf-8?
LinearLayout xmlns:androidhttp://schemas.android.com/apk/res/androidandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:orientationverticalandroid:backgrounddrawable/ic_background_radius //设置定义的圆角背景android:padding16dpRelativeLayoutandroid:layout_widthmatch_parentandroid:layout_height150dpImageViewandroid:idid/iv_face_compareandroid:layout_width150dpandroid:layout_height150dpandroid:layout_centerInParenttrueandroid:scaleTypecenterCropandroid:srcdrawable/ic_face_comparing2 /ImageViewandroid:idid/iv_scan_lineandroid:layout_width180dpandroid:layout_height3dpandroid:layout_alignParentToptrueandroid:layout_centerInParenttrueandroid:scaleTypecenterCropandroid:srcdrawable/ic_line_drawable //RelativeLayoutTextViewandroid:idid/tv_titleandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:layout_alignParentToptrueandroid:layout_centerInParenttrueandroid:gravitycenterandroid:text请正视前方android:textColorcolor/blackandroid:textSize16spandroid:textStylebold //LinearLayout
3、在MainAcitvity中写弹出AlertDialog的方法此处用的dialog是引用外部布局的方式要想去掉四角的白色背景框至关重要的一句是
tipDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); View tipInflate LayoutInflater.from(mContext).inflate(R.layout.dialog_face_compare_layout, null); //设置dialog显示的布局AlertDialog tipDialog new AlertDialog.Builder(mContext).setView(tipInflate).create();//创建AlertDialog对象tipDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));//将AlertDialog父组件的背景设置为透明色tipDialog.show(); //显示提示框
修改后效果图