安卓关于不能完全去除dialog的背景问题的解决方案

来源:互联网 发布:阿里云服务器 yum 编辑:程序博客网 时间:2024/06/07 07:30

现象:该设的属性都设了,但是还是有一层背景去不掉,如图

解决方案:递归去除背景,代码如下:

@Overridepublic void onStart() {    super.onStart();    View view=getDialog().getWindow().getDecorView();    clearBackground(view);}private void clearBackground(View view){    if (!(view instanceof ViewGroup)) {        view.setBackground(null);        return;    }    if(view.getId()==R.id.parentId)        return;    for (int i=0;i<((ViewGroup) view).getChildCount();i++)    {        view.setBackground(null);        clearBackground(((ViewGroup) view).getChildAt(i));    }}

1 0
原创粉丝点击