首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

.批改android选择壁纸来源列表

2012-08-11 
.修改android选择壁纸来源列表 在主界面按菜单键会弹出菜单,其中有一项是壁纸,当选择之后,出现一个选择器,

.修改android选择壁纸来源列表
 在主界面按菜单键会弹出菜单,其中有一项是壁纸,当选择之后,出现一个选择器,出现一个列表,这个不是dialog ,你可以选择是一般的壁纸,还是比较炫的动态壁纸或者是从设备中寻找存在的照片设置为你的桌面壁纸。startWallpaper  方法,看一下源码private void startWallpaper() {          closeAllApps(true);          final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);          Intent chooser = Intent.createChooser(pickWallpaper,                  getText(R.string.chooser_wallpaper));          // NOTE: Adds a configure option to the chooser if the wallpaper supports it          //       Removed in Eclair MR1  //        WallpaperManager wm = (WallpaperManager)  //                getSystemService(Context.WALLPAPER_SERVICE);  //        WallpaperInfo wi = wm.getWallpaperInfo();  //        if (wi != null && wi.getSettingsActivity() != null) {  //            LabeledIntent li = new LabeledIntent(getPackageName(),  //                    R.string.configure_wallpaper, 0);  //            li.setClassName(wi.getPackageName(), wi.getSettingsActivity());  //            chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li });  //        }          startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);      }  
其实是根据 Intent 调用相关的 Activity。 
final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);    Intent chooser = Intent.createChooser(pickWallpaper,                  getText(R.string.chooser_wallpaper));  

Intent.ACTION_SET_WALLPAPER 表示的含义以及它的真实值  查看api
public static final String ACTION_SET_WALLPAPER  Since: API Level 1  Activity Action: Show settings for choosing wallpaper  Input: Nothing.  Output: Nothing.  Constant Value: "android.intent.action.SET_WALLPAPER" 该 Intent 常量是一个 String,表示启用设置壁纸的 Activity,也就是说只要我们的系统中有这样的 Activity(action 为 android.intent.action.SET_WALLPAPER)就可以出现在选择器中。 
原生的 android 系统中有三个这样的 Activity 

1.WallpaperChooser.java


这是 Launcher 中的一个类,主要是选择壁纸的操作,和 Launcher.java 在一个包下面。通过 Launcher 的 Manifest.xml 文件就可以看到答案

</activity>  

<activity android:name="com.android.launcher2.WallpaperChooser" android:label="@string/pick_wallpaper" android:icon="@drawable/ic_launcher_wallpaper" android:screenOrientation="nosensor" android:finishOnCloseSystemDialogs="true">  

<intent-filter>  

<action android:name="android.intent.action.SET_WALLPAPER"/>  

<category android:name="android.intent.category.DEFAULT"/>  

</intent-filter>  

</activity>  

2..LiveWallpaperListActivity.java

位于 /packages/wallpapers/LivePicker/src/com/android/wallpaper/livepicker 下面,主要是选择动态壁纸。其 Manifest.xml 文件: 

<activity android:name="LiveWallpaperListActivity"  

            android:icon="@drawable/ic_launcher_live_wallpaper"  

            android:label="@string/live_wallpaper_picker_title"  

            android:theme="@android:style/Theme.NoTitleBar"  

            android:screenOrientation="nosensor">  

            <intent-filter>  

                <action android:name="android.service.wallpaper.LIVE_WALLPAPER_CHOOSER" />  

                <action android:name="android.intent.action.SET_WALLPAPER" />  

                <category android:name="android.intent.category.DEFAULT" />  

            </intent-filter>  

        </activity>  



3.Photographs.java


在以前的版本中,android 使用的是Gallery,现在改变为Gallery3D,位于/packages/apps/Gallery3D/src/com/cooliris/media,对应的 Manifest.xml 文件可自行查阅。

至此就明白了壁纸选择的原理

热点排行