1
好吧,我需要幫助添加設置以選擇要顯示的紋理 - 您應該能夠說出我的意思,因爲已經有兩個設置。我有gui的設置與活動一起,我只是無法弄清楚如何實現它。如果你能幫助我,我會在設置和市場帖子中的應用中稱讚你。隨着你的名字,網站,或無論在我的YouTube頻道的視頻。可以在這裏找到,youtube.com/motodroidhelpandinfo。我有超過1200個訂閱者。提前致謝。使用SharedPreference實現首選項,Android動態壁紙
這裏是我的偏好活動:
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) {}
}
而且這裏是我在主活動實現它的企圖。請注意,我無法適應整個活動的相關內容。另外,我希望設置在可以看到的紋理之間切換。我也使用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) {}
是的,只是覺得我說我仍然在尋找答案,或者甚至暗示大聲笑。 – TylerS 2010-09-03 06:45:18