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

 时间:2026-02-14 06:04:47

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
  • 热门搜索
    怎么样制作ppt 京东怎么货到付款 婴儿坐飞机怎么买票 银行流水怎么做 海市蜃楼是怎么形成的 小腿肌肉怎么减 怀孕了感冒怎么办 不来月经怎么调理 惋惜的近义词 感冒能健身吗