您的位置:首页 > 移动开发 > Android开发

Android从drawable中动态获取图片设置为XXXLayout背景

2013-06-18 10:37 603 查看
你drawable中的图片文件是统一规律命名的可以通过下面代码获取到

setImageResource(getResources().getIdentifier("文件名_" + "索引号", "drawable", "com.xxxx.xxxxx"));


索引号可以通过指定上下限的random获取

Random random = new Random();
String num = Integer.toString(random.nextInt(3));


然后就是是获取到当前activity的layout布局文件,给他设置背景

getWindow().getDecorView().setBackgroundResource(getResources().getIdentifier("splash" + num, "drawable", "com.wmh.colorfuldays"));
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Android