用于将任何图像设置为图库中的壁纸的代码

时间:2014-11-08 03:20:57

标签: android

Hlo,任何人都可以帮我解决这个问题。 。 我使用位图设置壁纸感到困惑。 ... 请看这里的代码 http://www.androidpeople.com/android-gallery-example

1 个答案:

答案 0 :(得分:0)

我查看了你展示的代码,我认为这不是最好的解决方案,只是因为它不是资源友好的。你会得到一系列的整数来保存你的绘图等等。总而言之,我我想,我想出了一个更好的解决方案。

我只会给你代码的重要部分,因为我很匆忙而且我真的没有时间写这一切,但如果你需要更多信息,请发表评论,我会来稍后回来。

Drawable thephoto;

//Important note!!!
//YOU need to add a OnClickListener to each view you got going there.I just added a clickListener to a variable yourView that I didn't even declare because i don't know what you got there ,but yourView ,in this case, can be a button,imageView,imageButton and so on.
//If you need more help with this, comment and whenever I am back,later on,I will answer gladly.
yourView.setOnClickListener(new onClickListener(View v){
    @override
    onTouch(View v){
     thepohoto = v.getResources().getDrawable(); 
     //if this doesn't work, go like this: the photo = v.getBackground();
  }
})
//Now you have the photo of the item you clicked.So you just set it.

WallpaperManager myWall = WallpaperManager.getInstance(getApplicationContext());
 try {
    myWall.setResource(thephoto); // change here give the selected image here
  } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
  }

总而言之,如果你了解它的基础知识并且你知道在哪里添加代码,这必须有效。