zoukankan      html  css  js  c++  java
  • android 设置壁纸几种方法


    总结一下,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();
            }
        }





  • 相关阅读:
    React Native从入门到放弃之坑总结
    React Native从入门到放弃之环境搭建
    flex弹性布局语法介绍及使用
    JavaScript ES6中export及export default的区别
    解决webstorm本地IP访问页面出错的问题
    UEFI+GPT与BIOS+MBR各自有什么优缺点?
    解决U盘拷贝时提示文件过大问题(不能拷贝超过4个g的文件)
    U盘安装原版Win7或Win8教程
    安装win8/win10提示无法在驱动器0分区上安装windows解决方法
    idea 编译报错 未结束的字符串字面值,非法的类型开始
  • 原文地址:https://www.cnblogs.com/happyxiaoyu02/p/6818958.html
Copyright © 2011-2022 走看看