Android API Demos 2.2 SetWallpaper, Translucent和TranslucentBlur
2010-10-19 20:16:10 来源:WEB开发网SetWallpaper
WallpaperManager是管理wallpaper的主要类,通过它我们可获取当前系统壁纸、设置壁纸等等。
示例中的主要代码:
Java代码
1. package com.example.android.apis.app;
2.
3. // Need the following import to get access to the app resources, since this
4. // class is in a sub-package.
5. import com.example.android.apis.R;
6.
7. import java.io.IOException;
8.
9. import android.app.Activity;
10. import android.app.WallpaperManager;
11. import android.graphics.Color;
12. import android.graphics.PorterDuff;
13. import android.graphics.drawable.Drawable;
14. import android.os.Bundle;
15. import android.view.View;
16. import android.view.WindowManager;
17. import android.view.View.OnClickListener;
18. import android.widget.Button;
19. import android.widget.ImageView;
20.
21. public class SetWallpaperActivity extends Activity {
22. final static private int[] mColors =
23. {Color.BLUE, Color.GREEN, Color.RED, Color.LTGRAY, Color.MAGENTA, Color.CYAN,
24. Color.YELLOW, Color.WHITE};
25.
26. @Override
27. protected void onCreate(Bundle savedInstanceState) {
28. super.onCreate(savedInstanceState);
29. setContentView(R.layout.wallpaper_2);
30. // 1.获取与给定Context关联的WallpaperManager
31. final WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
32. // 2.获取当前系统壁纸
33. final Drawable wallpaperDrawable = wallpaperManager.getDrawable();
34. final ImageView imageView = (ImageView) findViewById(R.id.imageview);
35. imageView.setDrawingCacheEnabled(true);
36. imageView.setImageDrawable(wallpaperDrawable);
更多精彩
赞助商链接