gpt4 book ai didi

java - 使用 SharedPreference 实现首选项,适用于 Android 动态壁纸

转载 作者:太空宇宙 更新时间:2023-11-04 14:26:25 25 4
gpt4 key购买 nike

好的,我需要帮助来添加设置以选择要显示的纹理 - 你应该能够明白我的意思,因为已经有两个设置。我有用于设置设置的 gui 以及我只是不知道如何实现它的 Activity 。如果你能帮助我,我会在应用程序的设置和市场帖子中将你归功于你。连同你的名字、网站或视频中我的 youtube channel 上的任何内容。可以在这里找到,youtube.com/motodroidhelpandinfo .我有超过 1,200 名订阅者。提前致谢。

这是我的首选 Activity :

package quotesandothers.livewallpaper.quotesandothers;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceActivity;

public class Settings extends PreferenceActivity implements
SharedPreferences.OnSharedPreferenceChangeListener {

@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
getPreferenceManager().setSharedPreferencesName(
livewallpaper.PREFERENCES);
addPreferencesFromResource(R.xml.wallpaper_settings);
getPreferenceManager().getSharedPreferences()
.registerOnSharedPreferenceChangeListener(this);
}

@Override
protected void onResume() {
super.onResume();
}

@Override
protected void onDestroy() {
getPreferenceManager().getSharedPreferences()
.unregisterOnSharedPreferenceChangeListener(this);
super.onDestroy();
}

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
String key) {}
}

这是我在主要 Activity 中实现它的尝试。请注意,我无法将相关的内容放入整个 Activity 中。此外,我希望设置在您可以看到的纹理之间发生变化。我还使用 andengine.org 作为主干。

@Override
public void onLoadResources() {
preferences = PreferenceManager.getDefaultSharedPreferences(this);
preferences.registerOnSharedPreferenceChangeListener(this);
this.mTexture = new Texture(2048, 2048, TextureOptions.DEFAULT);
this.mParallaxLayerMid1 = TextureRegionFactory.createFromAsset(
this.mAutoParallaxMotivationalTexture, this, "gfx/middle1.png",
0, 320);
this.mParallaxLayerTop = TextureRegionFactory.createFromAsset(
this.mAutoParallaxMotivationalTexture, this, "gfx/top.png", 0,
0);
this.mParallaxLayerTop2 = TextureRegionFactory.createFromAsset(
this.mAutoParallaxMotivationalTexture, this, "gfx/top2.png", 0,
173);
this.mParallaxLayerMid2 = TextureRegionFactory.createFromAsset(
this.mAutoParallaxMotivationalTexture, this, "gfx/middle2.png",
0, 450);
this.mParallaxLayerLow1 = TextureRegionFactory.createFromAsset(
this.mAutoParallaxMotivationalTexture, this, "gfx/lower1.png",
200, 574);
this.mParallaxLayerLow2 = TextureRegionFactory.createFromAsset(
this.mAutoParallaxMotivationalTexture, this, "gfx/lower2.png",
0, 740);
this.mEngine.getTextureManager().loadTextures(this.mTexture,
this.mAutoParallaxMotivationalTexture);
this.mTexture = new Texture(2048, 2048, TextureOptions.DEFAULT);
this.mParallaxLayerTopInspired = TextureRegionFactory.createFromAsset(
this.mAutoParallaxInspirationalTexture, this,
"gfx/topinspired.png", 0, 0);
}

public void OnSharedPreferenceChanged(SharedPreferences prefs, String key) {}

最佳答案

那里看起来一切正常。

我的应用程序只有一个不同之处,它基于立方体壁纸示例。

您获得首选项的这一行对我来说看起来不同。

preferences = PreferenceManager.getDefaultSharedPreferences(this);

我的:

preferences = myWallpaper.this.getSharedPreferences(SHARED_PREFS_NAME, 0);

试一试,看看会发生什么。

关于java - 使用 SharedPreference 实现首选项,适用于 Android 动态壁纸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3624111/

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