我已经找到了很多关于如何设置壁纸图像的教程,例如png。但我想要做的是在代码中制作我的壁纸,然后设置它。这是因为我希望用户能够调整壁纸(例如选择背景颜色等)。到目前为止我所拥有的是:
public class Landscape extends AppCompatActivity {
ValueAnimator skyAnimator;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_landscape);
skyAnimator = ObjectAnimator.ofInt(findViewById(R.id.sky), "backgroundColor", Color.rgb(0x00, 0x00, 0x4c), Color.rgb(0xae, 0xc2, 0xff));
skyAnimator.setDuration(10000);
skyAnimator.setEvaluator(new ArgbEvaluator());
skyAnimator.setRepeatCount(ValueAnimator.INFINITE);
skyAnimator.setRepeatMode(ValueAnimator.REVERSE);
skyAnimator.start();
}
public void setWallpaper(View view) {
Intent intent = new Intent(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);
intent.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT, new ComponentName(this, Landscape.class));
startActivity(intent);
}
不幸的是,当我点击setWallpaper时没有任何反应。有没有办法实现这个目标?它甚至可能吗?