Android中怎么使用WallPaper设置壁纸
今天就跟大家聊聊有关Android中怎么使用WallPaper设置壁纸,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

创新互联公司专注于招远企业网站建设,成都响应式网站建设公司,商城网站制作。招远网站建设公司,为招远等地区提供建站服务。全流程按需制作,专业设计,全程项目跟踪,创新互联公司专业和态度为您提供的服务
具体如下:
public class SetWallpaperActivity extends Activity {
// WallpaperManager类:系统壁纸管理。通过它可以获得当前壁纸以及设置指定图片作为系统壁纸。
private WallpaperManager wallpaperManager;
// 壁纸对应的Drawable
private Drawable wallpaperDrawable;
// 展示样式的ImageView
private ImageView imageView;
// 随机生成图片的颜色 Button
private Button randomize;
// 设置壁纸
private Button setWallpaper;
// 暂定的一些颜色值
final static private int[] mColors = { Color.BLUE, Color.GREEN, Color.RED,
Color.LTGRAY, Color.MAGENTA, Color.CYAN, Color.YELLOW, Color.WHITE };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.set_wallpaper);
// 初始化WallpaperManager
wallpaperManager = WallpaperManager.getInstance(this);
wallpaperDrawable = wallpaperManager.getDrawable();// 获得当前系统的壁纸
initViews();
initListeners();
}
private void initListeners() {
randomize.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
int mColor = (int) Math.floor(Math.random() * mColors.length);
// 给当前系统壁纸设置颜色
wallpaperDrawable.setColorFilter(mColors[mColor],
PorterDuff.Mode.MULTIPLY);// 取两层绘制交集
imageView.setImageDrawable(wallpaperDrawable);
// imageView.invalidate();
}
});
setWallpaper.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
try {
// 设置壁纸
wallpaperManager.setBitmap(imageView.getDrawingCache());
finish();
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
private void initViews() {
imageView = (ImageView) findViewById(R.id.imageview);
imageView.setDrawingCacheEnabled(true);
imageView.setImageDrawable(wallpaperDrawable);
randomize = (Button) findViewById(R.id.randomize);
setWallpaper = (Button) findViewById(R.id.setwallpaper);
}
}布局文件:
看完上述内容,你们对Android中怎么使用WallPaper设置壁纸有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注创新互联行业资讯频道,感谢大家的支持。
当前文章:Android中怎么使用WallPaper设置壁纸
文章分享:http://www.jxjierui.cn/article/jjgies.html


咨询
建站咨询
