0

我有多个图像,如果我使用WallpaperManager它,它会将壁纸设置为所谓的设置壁纸。我如何使用 toPhone 和 WallpaperManager?

Java 文件(如果需要):

 package hd.wallpaper.abs;

import java.io.IOException;

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

public class Main extends Activity implements View.OnClickListener {

    ImageView display;
    int toPhone;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_hd__wallpapers);
        toPhone = R.drawable.eye;

        display = (ImageView) findViewById(R.id.IVdisplay);
        ImageView image1 = (ImageView) findViewById(R.id.IVimage1);
        ImageView image2 = (ImageView) findViewById(R.id.IVimage2);
        ImageView image3 = (ImageView) findViewById(R.id.IVimage3);
        ImageView image4 = (ImageView) findViewById(R.id.IVimage4);
        ImageView image5 = (ImageView) findViewById(R.id.IVimage5);
        ImageView image6 = (ImageView) findViewById(R.id.IVimage7);
        Button setWall = (Button) findViewById(R.id.setwallpaperbutton);
        image1.setOnClickListener(this);
        image2.setOnClickListener(this);
        image3.setOnClickListener(this);
        image4.setOnClickListener(this);
        image5.setOnClickListener(this);
        image6.setOnClickListener(this);
        setWall.setOnClickListener(this);
    }

    public void onClick(View v) {
        // TODO Auto-generated method stub
        switch (v.getId()) {
        case R.id.IVimage1:
        display.setImageResource(R.drawable.i1);
        toPhone = R.drawable.i1;
        break;
        case R.id.IVimage2:
        display.setImageResource(R.drawable.i2);
        toPhone = R.drawable.i2;
        break;
        case R.id.IVimage3:
            display.setImageResource(R.drawable.i3);
            toPhone =R.drawable.i3;
            break;
        case R.id.IVimage4:
            display.setImageResource(R.drawable.i3);
            toPhone =R.drawable.i3;
            break;
        case R.id.IVimage5:
            display.setImageResource(R.drawable.i3);
            toPhone =R.drawable.i3;
            break;
        case R.id.IVimage7:
            display.setImageResource(R.drawable.i3);
            toPhone =R.drawable.solar;
            break;
        case R.id.setwallpaperbutton:
            final WallpaperManager myWallpaperManager
             = WallpaperManager.getInstance(getApplicationContext());
            final int fullWidth = myWallpaperManager.getDesiredMinimumWidth();
            final int fullHeight = myWallpaperManager.getDesiredMinimumHeight();
            try {
             myWallpaperManager.setResource(R.drawable.i1);
            } catch (IOException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
            }
            break;

        }

    }
    }
4

2 回答 2

0
case R.id.BsetWallpaper:
            InputStream first = getResources().openRawResource(toPhone);
      Bitmap close= BitmapFactory.decodeStream(first);      
      try{
          getApplicationContext().setWallpaper(close);
      }catch (IOException e){
          e.printStackTrace();
      }

hope help u.!

于 2012-12-11T04:27:32.720 回答
0

在你的代码中

final WallpaperManager myWallpaperManager = WallpaperManager.getInstance(getApplicationContext());
final int fullWidth = myWallpaperManager.getDesiredMinimumWidth();
final int fullHeight = myWallpaperManager.getDesiredMinimumHeight();
try {
myWallpaperManager.setResource(R.drawable.i1);

每次您将R.drawable.i1设置为墙纸时,只需使用toPhone更改它,它应该可以解决您的问题。

于 2014-01-28T08:08:43.207 回答