2014-11-08 101 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一切,這有工作,如果你瞭解它的基本功能,你知道在哪裏添加代碼。