我使用毕加索库为我的应用程序,它到目前为止工作得非常好。我有一个图像视图,它可以在卡片布局中从网页下载图像。我希望当用户点击图片时,它会将该图像设置为墙纸。 (我在这个PLZ中的一个菜鸟帮助了我,这是我打入的最后一件事。)
MainActivity.java
class CustomViewHolder extends RecyclerView.ViewHolder{
RibbonLayout ribbonLayout;
ImageView imageView;
public CustomViewHolder(View itemView) {
super(itemView);
ribbonLayout = (RibbonLayout)itemView.findViewById(R.id.ribbonLayout);
imageView = (ImageView)itemView.findViewById(R.id.imageView);
}
}
自定义视图持有者
public class CustomAdapter extends RecyclerView.Adapter<CustomViewHolder>{
Context context;
List<Item> itemList;
public CustomAdapter(Context context, List<Item> itemList) {
this.context = context;
this.itemList = itemList;
}
@Override
public CustomViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(context).inflate(R.layout.item_layout, parent, false);
return new CustomViewHolder(itemView);
}
@Override
public void onBindViewHolder(CustomViewHolder holder, int position) {
Item item = itemList.get(position);
if (item.type == 0) { //new
holder.ribbonLayout.setShowBottom(true);
holder.ribbonLayout.setShowBottom(true);
holder.ribbonLayout.setHeaderRibbonColor(Color.parseColor("white"));
holder.ribbonLayout.setHeaderTextColor(Color.parseColor("white"));
Picasso.with(context).load(item.imageURL)
.into(holder.imageView);
} else
if (item.type == 1) { //hot
holder.ribbonLayout.setShowBottom(false);
holder.ribbonLayout.setShowBottom(false);
holder.ribbonLayout.setHeaderRibbonColor(Color.parseColor("white"));
holder.ribbonLayout.setHeaderTextColor(Color.parseColor("white"));
Picasso.with(context).load(item.imageURL)
.into(holder.imageView);
}
else
if (item.type == 2) { //hot
holder.ribbonLayout.setShowBottom(false);
holder.ribbonLayout.setShowBottom(false);
Picasso.with(context).load(item.imageURL).into(holder.imageView);
}
}
@Override
public int getItemCount() {
return itemList.size();
}
CustomAdapter
protected override byte[] GenerateCode(string inputFileContent)
{
try
{
var result=Engine.Razor.RunCompile(inputFileContent,DateTime.Now.Ticks.ToString());
return System.Text.Encoding.UTF8.GetBytes(result);
}
catch (Exception e)
{
this.GeneratorError(4, e.ToString(), 1, 1);
//Returning null signifies that generation has failed
return null;
}
}
}
答案 0 :(得分:0)
您可以使用毕加索的结果设置壁纸。
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36'}
r = requests.get(urldet, headers=headers)
soup = BeautifulSoup(r.content, "lxml")
答案 1 :(得分:0)
在onClickListener
上设置ImageView
,从ImageView
获取可绘制内容,并将其设置为壁纸
holder.imageView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
try {
Bitmap bitmap = ((BitmapDrawable)((ImageView)view).getDrawable()).getBitmap();
WallpaperManager wallpaperManager = WallpaperManager.getInstance(context);
wallpaperManager.setBitmap(bitmap);
} catch (Exception e) {
e.printStackTrace();
}
}
});
确保将壁纸权限添加到清单和运行时
<uses-permission android:name="android.permission.SET_WALLPAPER"/>