gpt4 book ai didi

android - Android Studio:尝试基于Shared Pref更改背景,但在强制关闭时重置为默认背景

转载 作者:行者123 更新时间:2023-11-30 05:11:21 25 4
gpt4 key购买 nike

因此,我尝试基于Shared Preference onCreate更改背景,如下所示:

**strong text**
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_setting);
prefManager = new PrefManager(this);
String imagename = prefManager.getBg();
if (imagename=="1") {
RelativeLayout settinglin = (RelativeLayout) findViewById(R.id.settinglin);
settinglin.setBackgroundResource(R.drawable.lginbg);
} else if(imagename=="2") {
RelativeLayout settinglin = (RelativeLayout) findViewById(R.id.settinglin);
settinglin.setBackgroundResource(R.drawable.lginbgload);
etc...


此功能可以正常工作,但问题是,当强制关闭应用程序时,它总是将背景图片恢复为默认背景(在布局中)
例如:

android:background="@drawable/lginbg"


我检查强制关闭时未重置我的共享首选项的值(因此问题不在共享首选项中)

有人可以帮我解决这个问题吗

最佳答案

==测试引用是否相等(它们是否是同一对象)。

.equals()测试值是否相等(在逻辑上是否为“相等”)。

您应该改用equals。

if (imagename.equals("1"))

关于android - Android Studio:尝试基于Shared Pref更改背景,但在强制关闭时重置为默认背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53688494/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com