Android API Demos 2.2 SetWallpaper, Translucent和TranslucentBlur
2010-10-19 20:16:10 来源:WEB开发网37.
38. Button randomize = (Button) findViewById(R.id.randomize);
39. randomize.setOnClickListener(new OnClickListener() {
40. public void onClick(View view) {< pre name="code" class="xml">< style name="Theme.Translucent">
41. < item name="android:windowIsTranslucent">true< /item>
42. < item name="android:windowBackground">@drawable/translucent_background< /item>
43. < item name="android:windowNoTitle">true< /item>
44. < item name="android:colorForeground">#fff< /item>
45. < /style>< /pre>
46.
47. int mColor = (int) Math.floor(Math.random() * mColors.length);
48. // 3.对壁纸进行修改
49. wallpaperDrawable.setColorFilter(mColors[mColor], PorterDuff.Mode.MULTIPLY);
50. imageView.setImageDrawable(wallpaperDrawable);
51. imageView.invalidate();
52. }
53. });
54.
55. Button setWallpaper = (Button) findViewById(R.id.setwallpaper);
56. setWallpaper.setOnClickListener(new OnClickListener() {
57. public void onClick(View view) {
58. try {
59. // 4.设置壁纸
60. wallpaperManager.setBitmap(imageView.getDrawingCache());
61. finish();
62. } catch (IOException e) {
63. e.printStackTrace();
64. }
65. }
66. });
67. }
68. }
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;
更多精彩
赞助商链接