1.
//设置背景图片
String picfile= Environment.getExternalStorageDirectory() + “/pdp/pdp.png”;
try {
Drawable d = Drawable.createFromPath(picfile);
linearLayout.setBackground(d);
//Toast.makeText(getApplicationContext(), “设置背景图片成功!”, Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Toast.makeText(getApplicationContext(), “设置背景图片失败!”, Toast.LENGTH_SHORT).show();
}
2.
yourlayout.setBackgroundDrawable(new BitmapDrawable(BitmapFactory.decodeFile("图片路径")));
3.
网络图片:
Bitmap bitmap=BitmapFactory.decodeStream(new Url(url).openConnection().getInputStream()); button.setBackgroundDrawable(new BitmapDrawable(bitmap));