AlertDialog 背景透明
来源:互联网 发布:java调用 webservice 编辑:程序博客网 时间:2024/05/18 23:54
AlertDialog alertDialog; void showMagicDialog(int id){ AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.magicDialog); builder.setView(R.layout.dialog_layout); alertDialog = builder.create(); alertDialog.show(); Window w = alertDialog.getWindow(); Drawable bgDrawable = new ColorDrawable(0x00000000);//找到主布局控件, 并修改它的背景 w.getDecorView().findViewById(getIdFromInternalR("customPanel")).setBackground(bgDrawable); //窗体背景修改为透明 w.setBackgroundDrawable(bgDrawable); }
关于getIdFromInternalR("customPanel")
方法在下面.
public static int getIdFromInternalR(String idName){ try { Class clasz = Class.forName("com.android.internal.R$id"); Field field = clasz.getDeclaredField(idName); field.setAccessible(true); int id= (int)field.get(null); return id; } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (NoSuchFieldException e) { e.printStackTrace(); } return 0; }
如网上说的许多方法, 会调用getWindow().getDecorView().....然后修改背景
但不管用,
后面直接通过
ViewGroup vg = (ViewGroup)getDecorView();
for(int i = 0; i < vg.getChildCount(); i++)
找到ViewGroup则继续往下遍历, 每一个View都setBackgroundDrawable....
最终找到生效的是id/customPanel 和Window本身的background.
详细看源码中的PhoneWindow.java
PS: 仅在 RK 和 全志 , android4.2, 4.4上面测试通过!!!!
------------ GOOD LUCK ------------------
0 0
- AlertDialog 背景透明
- AlertDialog背景透明
- AlertDialog 背景颜色透明设置
- 【android】把AlertDialog后面黑背景设置全透明,昏暗度为0
- 透明背景
- 背景透明
- 背景透明
- 透明背景
- AlertDialog 透明全屏
- 关于AlertDialog的背景
- AlertDialog 自定义背景分析
- AlertDialog 自定义背景
- alertDialog的背景自定义
- 改变AlertDialog默认背景
- VC 控件背景透明、文字背景透明
- Flash背景透明(透明背景)设置方法
- 修改AlertDialog 按钮的背景
- 自定义AlertDialog去除黑色背景
- 基于netty实现的socks5代理协议
- Android 蓝牙状态获取
- 密码强度等级
- Android Wifi和蓝牙操作(一)
- Android Wifi和蓝牙操作(二)
- AlertDialog 背景透明
- android:windowIsTranslucent 导致 Activity切换动画无效
- Java 8的元空间(metaspace)
- ionic蓝牙用法
- 说Android中的多线程断点下载
- 7.Adapter-适配器模式
- CSS——生成随机数验证
- 心理学与生活
- iOS开发,TableViewCell上添加Xib创建的View会出现页面混乱