将背景图像设置为从一个活动到另一个活动的相对布局的代码
在第一个活动中,请参阅下面显示的代码
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
// TODO Auto-generated method stub
if(requestCode == 1011)
{
if(resultCode == RESULT_OK)
{
image.setImageURI(data.getData());
imageUri = data.getData();
String filePath[] = {MediaStore.Images.Media.DATA}; //A column name which to be return
Cursor c = getContentResolver().query(imageUri, filePath, null, null, null);
c.moveToFirst();
int index = c.getColumnIndex(filePath[0]);
String path = c.getString(index);//actual path of file in sa card
c.close();
if(path!=null)
{
//Bitmap bmp =BitmapFactory.decodeFile(path);
SharedPreferences.Editor editor = pref.edit();
editor.putString("image",path);//set the path of file into the SharedResources
editor.commit();
}
}
}
}
设置背景图像的代码
void setLayoutBackground()
{
SharedPreferences pref = getSharedPreferences("style_pref", 0);
String path = pref.getString("image",null);
Bitmap myBitmap = BitmapFactory.decodeFile(path);
BitmapDrawable d = new BitmapDrawable(getResources(),myBitmap);
layout.setBackgroundDrawable(d);
}