下面是Android的设置壁纸的一些代码(ApiDemo)

package com.example.android.apis.app;// Need the following import to get access to the app resources, since this// class is in a sub-package.import com.example.android.apis.R;import java.io.IOException;import android.app.Activity;import android.app.WallpaperManager;import android.graphics.Color;import android.graphics.PorterDuff;import android.graphics.drawable.Drawable;import android.os.Bundle;import android.view.View;import android.view.WindowManager;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.ImageView;/** * <h3>SetWallpaper Activity</h3> * * <p>This demonstrates the how to write an activity that gets the current system wallpaper, * modifies it and sets the modified bitmap as system wallpaper.</p> */public class SetWallpaperActivity extends Activity {    final static private int[] mColors =            {Color.BLUE, Color.GREEN, Color.RED, Color.LTGRAY, Color.MAGENTA, Color.CYAN,                    Color.YELLOW, Color.WHITE};    /**     * Initialization of the Activity after it is first created.  Must at least     * call {@link android.app.Activity#setContentView setContentView()} to     * describe what is to be displayed in the screen.     */    @Override    protected void onCreate(Bundle savedInstanceState) {        // Be sure to call the super class.        super.onCreate(savedInstanceState);        // See res/layout/wallpaper_2.xml for this        // view layout definition, which is being set here as        // the content of our screen.        setContentView(R.layout.wallpaper_2);        final WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);        final Drawable wallpaperDrawable = wallpaperManager.getDrawable();        final ImageView imageView = (ImageView) findViewById(R.id.imageview);        imageView.setDrawingCacheEnabled(true);        imageView.setImageDrawable(wallpaperDrawable);        Button randomize = (Button) findViewById(R.id.randomize);        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();            }        });        Button setWallpaper = (Button) findViewById(R.id.setwallpaper);        setWallpaper.setOnClickListener(new OnClickListener() {            public void onClick(View view) {                try {                    wallpaperManager.setBitmap(imageView.getDrawingCache());                    finish();                } catch (IOException e) {                    e.printStackTrace();                }            }        });    }}

更多相关文章

  1. 利用Handler来更新android的UI
  2. Android代码混淆官方实现方法
  3. material design 的android开源代码整理
  4. Animation
  5. Android百分比布局支持库
  6. Android(安卓)Studio代码混淆,开启Proguard,稍微总结一下
  7. Android(安卓)ListView 去除边缘阴影、选中色、拖动背景色、行高
  8. android image加载中等待动画
  9. android设置壁纸

随机推荐

  1. Android中的Ninja简介
  2. android 项目R文件丢失解决办法
  3. Android——android studio 安装完成之后
  4. Android(安卓)property属性机制
  5. Android 触控事件解析(Mastering the Andr
  6. Settings: android 组件如何响应语言变化
  7. 获取调试版SHA1和发布版SHA1的方法
  8. Android: Service中创建窗口Dialog
  9. Android Studio 查看不到SDK源码解决办法
  10. 2010-02-27 传智播客—Android(二)数据存储