android 设置壁纸几种方法
来源:互联网 发布:itunes下载的软件 编辑:程序博客网 时间:2024/05/11 21:37
总结一下,android中设置壁纸几种方法
方法一: 获取WallpaperManager实例
private void set_mytheme(int resid){ WallpaperManager wallpaperManager = WallpaperManager.getInstance(this); // Resources res = getResources(); try { wallpaperManager.setResource(resid); } catch (IOException e) { Toast.makeText(getApplicationContext(), "更换壁纸失败,强稍后重试", 200); } }
方法二:
private void set_mytheme(int resid){ getWindow().setBackgroundDrawableResource(int resid); }
方法三:
private synchronized void selectWallpaper(int position) { try { InputStream stream = getResources().openRawResource(IMAGE_IDS[position]); setWallpaper(stream); setResult(RESULT_OK); } catch (IOException e) { Log.e(LOG_TAG, "Failed to set wallpaper " + e); } }
方法四:
getWindow().setBackgroundDrawable(new ClippedDrawable(wallpaper));
/** * When a drawable is attached to a View, the View gives the Drawable its dimensions * by calling Drawable.setBounds(). In this application, the View that draws the * wallpaper has the same size as the screen. However, the wallpaper might be larger * that the screen which means it will be automatically stretched. Because stretching * a bitmap while drawing it is very expensive, we use a ClippedDrawable instead. * This drawable simply draws another wallpaper but makes sure it is not stretched * by always giving it its intrinsic dimensions. If the wallpaper is larger than the * screen, it will simply get clipped but it won't impact performance. */ private class ClippedDrawable extends Drawable { private final Drawable mWallpaper; public ClippedDrawable(Drawable wallpaper) { mWallpaper = wallpaper; } @Override public void setBounds(int left, int top, int right, int bottom) { super.setBounds(left, top, right, bottom); // Ensure the wallpaper is as large as it really is, to avoid stretching it // at drawing time mWallpaper.setBounds(left, top, left + mWallpaper.getIntrinsicWidth(), top + mWallpaper.getIntrinsicHeight()); } public void draw(Canvas canvas) { mWallpaper.draw(canvas); } public void setAlpha(int alpha) { mWallpaper.setAlpha(alpha); } public void setColorFilter(ColorFilter cf) { mWallpaper.setColorFilter(cf); } public int getOpacity() { return mWallpaper.getOpacity(); } }
- android 设置壁纸几种方法
- Android设置壁纸的几种方案
- android设置壁纸 的方法
- android 设置壁纸基本方法
- android-设置屏幕壁纸
- Android壁纸设置
- android 设置壁纸
- Android setWallpaper()设置壁纸
- Android设置壁纸
- Android Launcher 设置壁纸
- Android设置壁纸
- android 设置壁纸
- Android设置壁纸
- Android 壁纸设置 总结
- android-设置屏幕壁纸的两种方法(android.permission.SET_WALLPAPER)
- 设置Android默认壁纸为动态壁纸
- 设置Android默认壁纸为动态壁纸
- 设置Android默认壁纸为动态壁纸
- memcmp之优化
- WPF(ContentControl和ItemsControl)
- JAVA实现输出任意大小的等腰三角形
- Android操作系统11种传感器介绍
- hdu 4539 郑厂长系列故事——排兵布阵
- android 设置壁纸几种方法
- android 保持屏幕唤醒状态
- Android中的sp和wp指针
- 齐次坐标
- oracle 备份与恢复
- SchedulerFactoryBean 注入
- OO与设计模式的原则、目标
- Extjs 3.3 隐藏工具栏 出现Bug 的解决方法
- 不确定性原理的前世今生