Launcher modification-launcher's search box and protipwidget (widget modification) (there are pictures with truth)

Source: Internet
Author: User
Sometimes, for launcher development, you need to remove the search box and protipwidget on the launcher. In addition, protipwidget is added after Android 2.2. After searching for N for a long time, the original definition file is in launcher2/RES/XML/default_workspace.xml, and the file is pasted below:

<?xml version="1.0" encoding="utf-8"?><favorites xmlns:launcher="">    <!--  Far-left screen [0] -->    <!--  Left screen [1] -->    <appwidget        launcher:packageName=""        launcher:className=""        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=""        launcher:className=""        launcher:screen="2"        launcher:x="0"        launcher:y="1"        launcher:spanX="4"        launcher:spanY="1" />    <!--  Right screen [3] -->    <appwidget        launcher:packageName=""        launcher:className=""        launcher:screen="3"        launcher:x="0"        launcher:y="0"        launcher:spanX="4"        launcher:spanY="1" />    <appwidget        launcher:packageName=""        launcher:className=""        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" // number of screens Launcher: x = "0" // Launcher: y = "0"/> <appwidget Launcher: packagename = "com. android. protips "// The package name of the widget Launcher: classname =" com. android. protips. protipwidget "// display the widget Launcher: screen =" 2 "// number of screens Launcher: x =" 0 "// The Position of the icon X, which is 0 in the upper left corner, ascending to the right, 0-5 6 Launcher: Y = "1" // icon y position, 0 in the upper left corner, ascending downward, 0-2 3 Launcher: spanx = "4" // number of cells in the X direction Launcher: spany = "1"/>

These two are the search box we are looking for and protipwidget (I don't know how to translate them). Search is defined by Google in advance and we can use it directly here, in addition, there are clock (alarm clock) and so on.

If you want to add a shortcut to the launcher, OK, just add it in the above format, to see which one is not pleasing to the eye, just remove it.

Let's take a look at his:

How is the default_workspace.xml file parsed? In the source code of launcher2, there is a class of launcherprovider. Java (635 rows ),

 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 = != 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();                }

Here we provide File Parsing. You can see that the widget information is stored in the database. In addition, protipwidget is added after Android 2.2.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.