<?xml version="1.0" encoding="utf-8"?> <favorites xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher"> <!-- Far-left screen [0] --> <!-- Left screen [1] --> <appwidget launcher:packageName="com.google.android.apps.genie.geniewidget" launcher:className="com.google.android.apps.genie.geniewidget.miniwidget.MiniWidgetProvider" launcher:screen="1" launcher:x="0" launcher:y="0" launcher:spanX="4" launcher:spanY="1" /> <!-- Middle screen [2] --> <search launcher:screen="2" launcher:x="0" launcher:y="0" /> <appwidget launcher:packageName="com.android.protips" launcher:className="com.android.protips.ProtipWidget" launcher:screen="2" launcher:x="0" launcher:y="1" launcher:spanX="4" launcher:spanY="1" /> <!-- Right screen [3] --> <appwidget launcher:packageName="com.android.music" launcher:className="com.android.music.MediaAppWidgetProvider" launcher:screen="3" launcher:x="0" launcher:y="0" launcher:spanX="4" launcher:spanY="1" /> <appwidget launcher:packageName="com.android.vending" launcher:className="com.android.vending.MarketWidgetProvider" launcher:screen="3" launcher:x="1" launcher:y="1" launcher:spanX="2" launcher:spanY="2" /> <!-- Far-right screen [4] --> </favorites>
<!-- Middle screen [2] --> <search launcher:screen="2"//第几屏 launcher:x="0"// launcher:y="0" /> <appwidget launcher:packageName="com.android.protips"//widget所在的包名 launcher:className="com.android.protips.ProtipWidget"//所显示的widget launcher:screen="2"//第几屏 launcher:x="0"//图标x的位置,左上角x为0,向右递增,0-5共6个 launcher:y="1"//图标y的位置,左上角y为0,向下递增,0-2共3个 launcher:spanX="4"//在x方向上所占的格数 launcher:spanY="1" />这两个就是我们要找的搜索框和ProtipWidget(不知道该怎么翻译),search是google给我们提前定义好的,我们在这里直接使用就可以了,另外还有clock(闹钟)等。
如果想在launcher上面添加什么快捷方式,ok,自己仿照以上形式添加即可,看哪个不顺眼,除去即可。
我们可以看一下他的效果图:
而这个default_workspace.xml文件是如何被解析的呢?在launcher2的源代码里面有一个launcherProvider.java的类(635行),
XmlResourceParser parser = mContext.getResources().getXml(R.xml.default_workspace); AttributeSet attrs = Xml.asAttributeSet(parser); XmlUtils.beginDocument(parser, TAG_FAVORITES); final int depth = parser.getDepth(); int type; while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) { if (type != XmlPullParser.START_TAG) { continue; } boolean added = false; final String name = parser.getName(); TypedArray a = mContext.obtainStyledAttributes(attrs, R.styleable.Favorite); values.clear(); values.put(LauncherSettings.Favorites.CONTAINER, LauncherSettings.Favorites.CONTAINER_DESKTOP); values.put(LauncherSettings.Favorites.SCREEN, a.getString(R.styleable.Favorite_screen)); values.put(LauncherSettings.Favorites.CELLX, a.getString(R.styleable.Favorite_x)); values.put(LauncherSettings.Favorites.CELLY, a.getString(R.styleable.Favorite_y)); if (TAG_FAVORITE.equals(name)) { added = addAppShortcut(db, values, a, packageManager, intent); } else if (TAG_SEARCH.equals(name)) { added = addSearchWidget(db, values); } else if (TAG_CLOCK.equals(name)) { added = addClockWidget(db, values); } else if (TAG_APPWIDGET.equals(name)) { added = addAppWidget(db, values, a, packageManager); } else if (TAG_SHORTCUT.equals(name)) { added = addUriShortcut(db, values, a); } if (added) i++; a.recycle(); }