,如果你想改变的背景,活动的布局,我认为,你可以做到这一点使用的setBackground方法的布局,例如:
activityLayout = (LinearLayout)findViewById(R.id.tableLayout1);
activityLayout.setBackgroundDrawable(getResources().getDrawable(R.id.somedrawable))
可以使用例如SharedPreference存储的背景图像,然后当您启动活动时,您会阅读包含背景的首选项。例如,当用户选择了背景:
SharedPreferences myPrefs = this.getSharedPreferences("myPrefs", Context.MODE_PRIVATE);
SharedPreferences.Editor prefsEditor = myPrefs.edit();
prefEditor.putInt("backgroudResourceId", userchoice);
prefEditor.commit();
而当活动开始,你必须阅读从SharedPreference的RESOURCEID:
SharedPreferences myPrefs = this.getSharedPreferences("myPrefs", Context.MODE_PRIVATE);
drawableid = myPrefs.getInt("backgroundResourceId", defaultvalue);
yourlayout.setBackground(drawableid);
,其中默认值是默认值,如果首选项没有设置。应该初始化yourLayout(以与活动布局相同的方式)。
谢谢Ivane,我知道这一点,但让我说我有20个活动,当用户设置背景图像时,如何更改它们的全部空间。 –
安娜检查我的编辑。 – Ivan
谢谢Ivan,现在,当用户更改背景图片并退出应用程序时。然后他会回来,会再出现一次旧的背景,而不是新的背景? –