天天看着模拟器里面的那个图片感觉很恼火,所以干脆想将其换掉,顺便学一点知识
下面是一个设置模拟器壁纸的例子
1、使用本地图片的方式设置壁纸
SetWallpaper.java
package com.loulijun.setwallpaper;
import java.io.IOException;
import android.app.Activity;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
public class SetWallpaper extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res =getResources();
BitmapDrawable bmp = (BitmapDrawable)res.getDrawable(R.drawable.gaoyuanyuan);
Bitmap b = bmp.getBitmap();
try {
setWallpaper(b);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
另外,在main.xml中加入权限
<uses-permission android:name="android.permission.SET_WALLPAPER" />
运行结果如下:
由于图片较大,所以设置的时候需要找一张适合模拟器大小的图片即可