0

画像の壁紙の設定方法フル画像の背景画面。私のコード

Bitmap bmap = BitmapFactory.decodeResource(getResources(),
                    R.drawable.splash);

            DisplayMetrics outMetrics = new DisplayMetrics();
            getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
            int w = outMetrics.widthPixels;
            int h = outMetrics.heightPixels;
            Bitmap wallpaper=Bitmap.createScaledBitmap(bmap, w, h, true);

                            WallpaperManager m = WallpaperManager.getInstance(getApplicationContext());
            try {
                m.setBitmap(wallpaper);
            } catch (IOException e) {
                e.printStackTrace();
            }

画像

画像

I need image full set a wall paper

4

2 に答える 2

1
public void changeWallpaper(String path) {
   FileInputStream is;
         BufferedInputStream bis;
                WallpaperManager wallpaperManager;
                Drawable wallpaperDrawable;
                File sdcard = Environment.getExternalStorageDirectory();
                try {
                        is = new FileInputStream(new File(path));
                        bis = new BufferedInputStream(is);
                        Bitmap bitmap = BitmapFactory.decodeStream(bis);
                        Bitmap useThisBitmap = Bitmap.createBitmap(bitmap);
                        wallpaperManager = WallpaperManager.getInstance(MainActivity.this);
                        wallpaperDrawable = wallpaperManager.getDrawable();
                        wallpaperManager.setBitmap(useThisBitmap);
                } catch (Exception e) {
                        e.printStackTrace();
                }
    }

上記のコードは私のために機能し、追加することを忘れないでください

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

AndroidManifest.xml ファイル内

ドローアブルをビットマップに変換することもできます

BitmapFactory.decodeResource(context.getResources(), R.drawable.icon_name);
于 2013-10-31T10:57:02.373 に答える