WallpaperManager不是可以getDrawable么,你直接用这个drawable对象设置为activity的背景,可以去调用activity的setbackground吧
解决方案 »
- SharedBufferStack(126): waitForCondition(LockCondition) timed out.
- android源码
- 如何在程序中模拟gps坐标改变?
- 请教高手一个view的难题!!!!!!!!!
- 关于SimpleJNI.apk问题
- Date/Calendar/System三者的时间各不相同,求解释
- android调用webservice出现java.io.IOException
- 两个子线程间,怎么传递变量值呢?
- Android平台是不是不能同时预览两个镜头?
- android 通知栏图标自动变色如何实现
- android平台蓝牙文件传输
- android平台下的手机重力感应分析
Drawable drawable = this.getWallpaper();我这样只拿到当前桌面的壁纸,因为我是仿照android源代码,WallpaperChooser.java是用来设置壁纸的,内容如下:public class WallpaperChooser extends Activity implements
AdapterView.OnItemSelectedListener, OnClickListener { private Gallery mGallery;
private ImageView mImageView;
private boolean mIsWallpaperSet; private Bitmap mBitmap; private ArrayList<Integer> mThumbs;
private ArrayList<Integer> mImages;
private WallpaperLoader mLoader; @Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
requestWindowFeature(Window.FEATURE_NO_TITLE); findWallpapers(); setContentView(R.layout.wallpaper_chooser); mGallery = (Gallery) findViewById(R.id.gallery);
mGallery.setAdapter(new ImageAdapter(this));
mGallery.setOnItemSelectedListener(this);
mGallery.setCallbackDuringFling(false); findViewById(R.id.set).setOnClickListener(this); mImageView = (ImageView) findViewById(R.id.wallpaper);
} private void findWallpapers() {
mThumbs = new ArrayList<Integer>(24);
mImages = new ArrayList<Integer>(24); final Resources resources = getResources();
final String packageName = getApplication().getPackageName(); addWallpapers(resources, packageName, R.array.wallpapers);
} private void addWallpapers(Resources resources, String packageName, int list) {
final String[] extras = resources.getStringArray(list);
for (String extra : extras) {
int res = resources.getIdentifier(extra, "drawable", packageName);
if (res != 0) {
final int thumbRes = resources.getIdentifier(extra + "_small",
"drawable", packageName); if (thumbRes != 0) {
mThumbs.add(thumbRes);
mImages.add(res);
}
}
}
} @Override
protected void onResume() {
super.onResume();
mIsWallpaperSet = false;
} @Override
protected void onDestroy() {
super.onDestroy(); if (mLoader != null
&& mLoader.getStatus() != WallpaperLoader.Status.FINISHED) {
mLoader.cancel(true);
mLoader = null;
}
} public void onItemSelected(AdapterView parent, View v, int position, long id) {
if (mLoader != null
&& mLoader.getStatus() != WallpaperLoader.Status.FINISHED) {
mLoader.cancel();
}
mLoader = (WallpaperLoader) new WallpaperLoader().execute(position);
} /*
* When using touch if you tap an image it triggers both the onItemClick and
* the onTouchEvent causing the wallpaper to be set twice. Ensure we only
* set the wallpaper once.
*/
private void selectWallpaper(int position) {
if (mIsWallpaperSet) {
return;
} mIsWallpaperSet = true;
// try { WallpaperManager wpm = (WallpaperManager) getSystemService(WALLPAPER_SERVICE);
//wpm.setResource(mImages.get(position));
setResult(RESULT_OK);
finish();
// } catch (IOException e) {
// }
} public void onNothingSelected(AdapterView parent) {
} private class ImageAdapter extends BaseAdapter {
private LayoutInflater mLayoutInflater; ImageAdapter(WallpaperChooser context) {
mLayoutInflater = context.getLayoutInflater();
} public int getCount() {
return mThumbs.size();
} public Object getItem(int position) {
return position;
} public long getItemId(int position) {
return position;
} public View getView(int position, View convertView, ViewGroup parent) {
ImageView image; if (convertView == null) {
image = (ImageView) mLayoutInflater.inflate(
R.layout.wallpaper_item, parent, false);
} else {
image = (ImageView) convertView;
} int thumbRes = mThumbs.get(position);
image.setImageResource(thumbRes);
Drawable thumbDrawable = image.getDrawable();
if (thumbDrawable != null) {
thumbDrawable.setDither(true);
} else {
}
return image;
}
} public void onClick(View v) {
selectWallpaper(mGallery.getSelectedItemPosition());
} class WallpaperLoader extends AsyncTask<Integer, Void, Bitmap> {
BitmapFactory.Options mOptions; WallpaperLoader() {
mOptions = new BitmapFactory.Options();
mOptions.inDither = false;
mOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;
} protected Bitmap doInBackground(Integer... params) {
if (isCancelled())
return null;
try {
return BitmapFactory.decodeResource(getResources(), mImages
.get(params[0]), mOptions);
} catch (OutOfMemoryError e) {
return null;
}
} @Override
protected void onPostExecute(Bitmap b) {
if (b == null)
return; if (!isCancelled() && !mOptions.mCancel) {
// Help the GC
if (mBitmap != null) {
mBitmap.recycle();
} final ImageView view = mImageView;
view.setImageBitmap(b); mBitmap = b; final Drawable drawable = view.getDrawable();
drawable.setFilterBitmap(true);
drawable.setDither(true); view.postInvalidate(); mLoader = null;
} else {
b.recycle();
}
} void cancel() {
mOptions.requestCancelDecode();
super.cancel(true);
}
}
}在selectWallpaper()方法中,我这里肯定不应该是这样写,因为这样写,仍然只是为Launcher桌面设置了壁纸,但是我想让为我自己的Activity设置壁纸。应该怎么修改?
finish只是关闭了当前的Activity,我原始的那个Activity还存在。