下面是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. Android(安卓)ListView 去除边缘阴影、选中色、拖动背景色、行高
  2. android image加载中等待动画
  3. android为图片生成缩略图
  4. android中设置AlertDialog的大小 .
  5. 对话框式activity
  6. Android自定义相机,切换前后摄像头,照相机拍照
  7. [转]Android(安卓)Audio简述
  8. android 动态设置Activity 的切换方向
  9. Android中进行HTTP操作

随机推荐

  1. android:manageSpaceActivity让应用手动
  2. Android 盘点所有Dialog 对话框 大合集
  3. 写给初学者Android AIDL必看内容
  4. [译]Android的垄断和如何利用它
  5. Android原生(Native) C开发之一 环境搭建
  6. Android 使用Parcelable传递对象
  7. Android(安卓)studio 使用心得(四)---and
  8. 虚拟机Dalvik
  9. Android ListView 滚动的N种方法
  10. Android设备adb调试