我可以做第1步和第2步非常容易我只是坚持其他两个步骤可以任何人指出我正确的方向。 这是迄今为止的代码
public class MainActivity extends Activity implements OnClickListener {
ImageView iv;
Button b;
Intent i;
Bitmap bmp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initialize();
InputStream is = getResources().openRawResource(R.drawable.image);
bmp = BitmapFactory.decodeStream(is);
}
private void initialize(){
iv = (ImageView) findViewById(R.id.ivReturnedPic);
b = (Button) findViewById(R.id.bSetWallpaper);
b.setOnClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()){
case R.id.bSetWallpaper:
try {
getApplicationContext().setWallpaper(bmp);
} catch (IOException e) {
e.printStackTrace();
}
break;
}
}
}
答案 0 :(得分:0)
将壁纸设置为所需的屏幕尺寸
WallpaperManager myWallpaperManager = WallpaperManager.getInstance(getApplication());
int height = myWallpaperManager.getDesiredMinimumHeight();
int width = myWallpaperManager.getDesiredMinimumWidth();
try {
myWallpaperManager.setBitmap(Bitmap.createScaledBitmap(setAs, width , height , true));
} catch (final IOException e) {
Toast.makeText(getApplication(), "Error setting wallpaper", Toast.LENGTH_SHORT).show();
}
关于第四个问题,请参阅this