• 获取桌面的壁纸来设成背景


    第一种方法,可直接设置主题,

    下面重点介绍第二种方法:

    1. // 获取壁纸管理器   
    2.             WallpaperManager wallpaperManager = WallpaperManager  
    3.                     .getInstance(mContext);  
    4.             // 获取当前壁纸   
    5.             Drawable wallpaperDrawable = wallpaperManager.getDrawable();  
    6.             // 将Drawable,转成Bitmap   
    7.             Bitmap bm = ((BitmapDrawable) wallpaperDrawable).getBitmap();  
    8.   
    9.             // 需要详细说明一下,mScreenCount、getCurrentWorkspaceScreen()、mScreenWidth、mScreenHeight分别   
    10.             //对应于Launcher中的桌面屏幕总数、当前屏幕下标、屏幕宽度、屏幕高度.等下拿Demo的哥们稍微要注意一下   
    11.             float step = 0;  
    12.             // 计算出屏幕的偏移量   
    13.             step = (bm.getWidth() - LauncherPreferenceModel.mScreenWidth)  
    14.                     / (LauncherPreferenceModel.mScreenCount - 1);  
    15.             // 截取相应屏幕的Bitmap   
    16.             Bitmap pbm = Bitmap.createBitmap(bm, (int) (mLauncher  
    17.                     .getCurrentWorkspaceScreen() * step), 0,  
    18.                     (int) (LauncherPreferenceModel.mScreenWidth),  
    19.                     (int) (LauncherPreferenceModel.mScreenHeight));  
    20.             // 设置 背景   
    21.             layout.setBackgroundDrawable(new BitmapDrawable(pbm));  
  • 相关阅读:
    UVA657 The die is cast(DFS、BFS)
    三分
    【洛谷P6105】iepsmCmq
    【CF613D】Kingdom and its Cities
    【洛谷P4294】游览计划
    【洛谷P3500】TESIntelligence Test
    【洛谷P6189】[NOI Online 入门组] 跑步
    【洛谷P2973】Driving Out the Piggies
    【洛谷P3164】和谐矩阵
    【洛谷P4161】游戏
  • 原文地址:https://www.cnblogs.com/lyz459/p/2797326.html
Copyright © 2020-2023  润新知