私は、次のコードを使用しています:どのようにすべての活動の永久的な背景を設定するには?
Public void xyz(View v) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), 0);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch(requestCode){
case 0:
data.getDataString();
if(resultCode == RESULT_OK){
try {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(_activity.getContentResolver(), data.getDataString());
RelativeLayout bg = (RelativeLayout) findViewById(R.id.might);
Drawable drawable = new BitmapDrawable(getResources(), bitmap);
bg.setBackgroundDrawable(drawable);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch blocke.printStackTrace();
} catch(IOException e) {
// TODO Auto-generated catch blocke.printStackTrace();
}
}
break;
}
}
質問:
それが唯一の活動の背景を設定します。
onDestroy()
メソッドの後、再起動時にデフォルトの背景を設定します。
コードの書式を学ぶ:http://meta.stackexchange.com/questions/22186/how-do-i-format-my-code-blocks –
あなたはすべてのスーパークラスであるアクティビティクラスを書くことができますあなたの他のアクティビティ –
選択したイメージのURLをシングルトンクラス/ SharedPreferencesに保存し、アクティビティが作成されたときに読み込むことができます。おそらくPicassoのようなライブラリのキャッシュを使って、画像がメモリに残っていれば読み込まないようにすることもできます。 –