在单击按钮时从imageview设置背景-Android

在单击按钮时从imageview设置背景-Android,android,button,imageview,Android,Button,Imageview,我的项目中有一个Imageview和一个按钮,我希望该按钮将图像设置为主屏幕背景,但当我按下该按钮时,它什么也不做,没有错误或强制关闭 谢谢 package com.example.androidhive; import java.io.IOException; import android.app.Activity; import android.app.WallpaperManager; import android.content.Intent; import android.os.B

我的项目中有一个Imageview和一个按钮,我希望该按钮将图像设置为主屏幕背景,但当我按下该按钮时,它什么也不做,没有错误或强制关闭

谢谢

package com.example.androidhive;

import java.io.IOException;

import android.app.Activity;
import android.app.WallpaperManager;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

 public class FullImageActivity extends Activity {

 @Override
 public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.full_image);

    // get intent data
    Intent i = getIntent();

    // Selected image id
    int position = i.getExtras().getInt("id");
    ImageAdapter imageAdapter = new ImageAdapter(this);

    ImageView imageView = (ImageView) findViewById(R.id.full_image_view);
    imageView.setImageResource(imageAdapter.mThumbIds[position]);
    }


 public void setaswall(View view) { // SET AS WALLPAPER BUTTON
     WallpaperManager myWallpaperManager 
     = WallpaperManager.getInstance(getApplicationContext());
     };
  }

使用获取壁纸管理器

WallpaperManager wallpaperManager = WallpaperManager.getInstance(getApplicationContext());
要获取imageView位图并设置为墙纸,请使用

Bitmap bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap();
wallpaperManager.setBitmap(bitmap);
或者,如果您有图像资源id(如代码示例中所示),则可以直接使用

wallpaperManager.setResource(imageAdapter.mThumbIds[position]);

您只有
wallpermanager mywallpermanager=wallpermanager.getInstance(getApplicationContext())在哪里设置图像?没有代码使用
MyWallperManager.setBitmap(位图)
在您的按钮中单击,如果您在stackoverflow
Bitmap Bitmap=BitmapFactory.decodeResource(getResources(),R.drawable.ic_laucnher)上进行谷歌搜索或搜索,您将获得更多信息
然后
mywallpermanager.setBitmap(位图)
要了解更多信息,请阅读文档和谷歌搜索我不能在我的代码中使用它!!我想从imageview设置图像!!!imageView不能被重新调用imageView imageView=(imageView)findViewById(R.id.full\u image\u view);