android怎么设置背景?android背景设置教程

 时间:2026-05-01 21:38:40

1、public static final String TAG = "WallpaperActivity";/*** 背景图片名称*/private static final String FILE_NAME = "MM-320x480.png";/*** @see android.app.Activity#onCreate(android.os.Bundle)*/public void onCreate(Bundle cycle) {super.onCreate(cycle);super.setContentView(R.layout.wallpaper);

android怎么设置背景?android背景设置教程

2、// 取得背景图片Bitmap wallpaper = this.getWallpager();

android怎么设置背景?android背景设置教程

3、// 设置桌面背景this.putWallpaper(wallpaper);}

android怎么设置背景?android背景设置教程

4、/*** 取得SDCard中的背景图片*/private Bitmap getWallpager() {// SDCard的路径,也就是“/sdcard/”File root = Environment.getExternalStorageDirectory();// MM图片File wall = new File(root, FILE_NAME);// MM图片路径String path = wall.getAbsolutePath();Log.d(TAG, "MM文件路径为:" + path);return BitmapFactory.decodeFile(path);}

android怎么设置背景?android背景设置教程

5、/*** 设置桌面背景

* www.cnxuwen.com*/private void putWallpaper(Bitmap bitmap) {try {WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);wallpaperManager.setBitmap(bitmap);} catch (IOException e) {String msg = "设置桌面背景发生异常:" + e.getLocalizedMessage();Log.e(TAG, "设置桌面背景发生异常!", e);Toast.makeText(this, msg, Toast.LENGTH_LONG).show();}

}

android怎么设置背景?android背景设置教程

6、增加权限,在AndroidManifest.xml文件中增加设置桌面背景权限:

<!-- 设置桌面背景的权限 -->

< uses-permission android:name ="android.permission.SET_WALLPAPER" />

android怎么设置背景?android背景设置教程

  • 王者荣耀怎么练好小乔
  • 王者荣耀积分怎么送好友
  • 东方耀怎么连招
  • 王者荣耀无双令在哪兑换道具
  • 皮队友怎么绑定QQ
  • 热门搜索
    look at是什么意思 成都有什么特产 涉警人员是什么意思啊 商务专员是做什么的 什么让我陶醉作文 落地签是什么意思 一颦一笑是什么意思 什么是论据 好友克隆是什么意思 如沐春风是什么意思