【问题标题】:how to set up a wallpaper app using firebase recyclerview?如何使用 firebase recyclerview 设置壁纸应用程序?
【发布时间】:2019-05-23 12:32:49
【问题描述】:

我创建了一个壁纸应用程序,我正在使用Firebase 将图像上传到数据库并显示给RecyclerView

我可以通过RecyclerView 看到我在Firebase 中上传的图像,我还可以将该图像传递给另一个活动。

但我的问题是,我无法将图像设置为墙纸,当我设置按钮时图像消失了。

我设置壁纸的代码:

 img = (ImageView) findViewById(R.id.images);
    Intent intent  = getIntent();
    String webUrl = intent.getStringExtra("URL");
    Picasso.get().load(webUrl).into(img);

    fab1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            WallpaperManager wallpaper = WallpaperManager.getInstance(getApplicationContext());
            try {
               wallpaper.setResource(+ R.drawable.pug);  //by using this code i can set a image in directory a wallpaper
                //wallpaper.setResource(+ R.id.images); //i tried this one it doesn't work it just crashes the app

            }catch (IOException e){
                e.printStackTrace();
            }
        }
    });

我想要设置ImageView 中显示的任何图像 有什么办法

【问题讨论】:

  • 可以将图片直接设置成imageview。
  • 如何编码

标签: java android firebase android-adapter android-wallpaper


【解决方案1】:

我假设您已经获得了此权限:

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

我不确定您要达到什么目的,但我假设您希望用户从列表中选择一张图片并将其设置为墙纸。 您只能将BitmapResource ID 传递给WallpaperManager。在这种情况下,首先将图像作为Bitmap 获取,然后加载到ImageView

由于您已经在使用毕加索,您可以这样做:

Picasso.with(this).load(webUrl).centerCrop().into(new Target() { 
    @Override 
    public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) { 
        wallpaper.setBitmap(bitmap);
    }
}

【讨论】:

  • 我想在我在这里给出的 onclick 上将 imageview 中的图像设置为墙纸 ``` public void onClick(View view) { WallpaperManager wallpaper = WallpaperManager.getInstance(getApplicationContext());试试 {壁纸.setResource(+ R.drawable.pug); //通过使用此代码,我可以在壁纸目录中设置图像 //wallpaper.setResource(+ R.id.images); //我试过这个它不起作用它只是让应用程序崩溃 }catch (IOException e){ e.printStackTrace(); } ```
  • 这就是我刚才解释的。将我的代码放入onClick 方法中。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多