想用SD卡上的图片做Activity背景 我想使用SD卡上的指定文件作为Activity和其它控件的背景,这样的话,我只需要更换图片就可以换背景了,要实现这个功能,请问一手该怎么做?我看到的方法,都是需要把图片放到程序的资源库中,这样一来程序会变得很大,二来不能更换,故请教 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可以先把文件转化为字节数组,再转为bitmap,再转为BitmapDrawable,此类是Drawable的子类可以直接设为背景写了个一段小代码,LZ可以参考下try { LinearLayout ll = (LinearLayout)this.findViewById(R.id.line); File file = new File(Environment.getExternalStorageDirectory()+"/device.png"); InputStream inputStream = new FileInputStream(file); long length = file.length(); byte[] bytes = new byte[(int)length]; int offset = 0; int numRead = 0; while (offset < bytes.length && (numRead= inputStream.read(bytes, offset, bytes.length-offset)) >= 0) { offset += numRead; } Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length); BitmapDrawable bd= new BitmapDrawable(this.getResources(), bitmap); ll.setBackgroundDrawable(bd); } catch (Exception e) { e.printStackTrace(); } 呵呵,回楼上,谢谢了,俺已经搞定了:)不过还是非常感谢:)代码如下:Bitmap bm = BitmapFactory.decodeFile("/sdcard/title.jpg", new Options());BitmapDrawable bd = new BitmapDrawable(bm);ly.setBackgroundDrawable(bd); 两个Activity跳转的问题。 android wifi问题 android 内存问题 android widget动画效果 关于Android内置的搜索框 android编辑联系人 请教如何在Service中关闭调用它的Activity? android开发网络应用,求思路 怎么在异步线程中实现Activity之间的跳转 QQ互联登录,获取用户信息时导入Constans包一直不对,不知道啥原因。 关于调用Android自带图片浏览器的问题 android城市名称获取经度和纬度
写了个一段小代码,LZ可以参考下try {
LinearLayout ll = (LinearLayout)this.findViewById(R.id.line);
File file = new File(Environment.getExternalStorageDirectory()+"/device.png");
InputStream inputStream = new FileInputStream(file);
long length = file.length();
byte[] bytes = new byte[(int)length];
int offset = 0;
int numRead = 0;
while (offset < bytes.length &&
(numRead= inputStream.read(bytes, offset, bytes.length-offset)) >= 0)
{
offset += numRead;
}
Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
BitmapDrawable bd= new BitmapDrawable(this.getResources(), bitmap);
ll.setBackgroundDrawable(bd);
} catch (Exception e) {
e.printStackTrace();
}
不过还是非常感谢:)
代码如下:
Bitmap bm = BitmapFactory.decodeFile("/sdcard/title.jpg", new Options());
BitmapDrawable bd = new BitmapDrawable(bm);
ly.setBackgroundDrawable(bd);