2014-11-08 104 views
0

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

+0

检查:http://stackoverflow.com/questions/26735180/crash-when-i-use-method-setwallpaper-android/26735713#26735713 – 2014-11-08 03:58:58

+0

@CodeZero具有u知道如何从图库 – 2014-11-08 04:39:14

+0

这里我指的PIC图像作为壁纸收集apk中的图片库... 我知道每次只为一个图像设置壁纸:( 我使用了一个按钮setOnClickListener然后它里面我使用了墙纸管理器,我给它的资源为R.drawable .a_1。。。 这只设置image.ie。image a_1 – CodeZero 2014-11-08 04:52:36

回答

0

你已经证明,我不认为这是最好的解决方案,仅仅是因为没有资源friendly.You获得的int数组来保存你的drawables等等。总而言之,我想出了一个更好的解决方案。

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

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(); 
    } 

所有N一切,这有工作,如果你了解它的基本功能,你知道在哪里添加代码。