This article describes the common default configuration modification methods of Launcher3 in Android development. Share it for your reference, as follows:
Launcher Overview
Launcher is the first application to be launched after booting, which is used to display application lists, shortcuts, widgets, etc. Launcher is the first application (the first application to be launched after booting) to display it to users. The quality of its design affects the user's experience and even affects the user's judgment of purchasing the machine. Therefore, many brand manufacturers will spare no effort to deeply customize Launcher, such as Xiaomi's MIUI, Huawei's EMUI, etc. Android's default Launcher is not customized too much, it is more concise and is sought after by the Yuansheng Party. Google's Nexus series of mobile phones basically use Yuansheng Launcher. Currently, Android's Launcher version is Launcher3, and the subsequent related content is also based on Launcher3.
Launcher3 default configuration modification
1. How to set the default page
res/values/
<integer name="config_workspaceDefaultScreen">0</integer>
On the Launcher3 desktop, no matter which page it is on, press the HOME key and it will return to the default page.
2. How to hide the search box in launcher3
① In Launcher3/src/com/android/launcher3/
Comment the updateGlobalIcons() method call, there are two places in total.
public View getQsbBar() { if (mQsbBar == null) { mQsbBar = (.search_bar, mSearchDropTargetBar, false); - (mQsbBar); } + (); return mQsbBar; } @Override public void bindSearchablesChanged() { //Annotate the content of this method/* boolean searchVisible = updateGlobalSearchIcon(); boolean voiceVisible = updateVoiceSearchIcon(searchVisible); if (mSearchDropTargetBar != null) { (searchVisible, voiceVisible); } */ }
② In Launcher3/src/com/android/launcher3/
// Layout the search bar //Notes as follows/* View qsbBar = (); LayoutParams vglp = (); = LayoutParams.MATCH_PARENT; = LayoutParams.MATCH_PARENT; (vglp); */
③ In Launcher3/res/values/
- <dimen name="dynamic_grid_search_bar_height">48dp</dimen>
+ <dimen name="dynamic_grid_search_bar_height">18dp</dimen>
You can see the effect after recompiling.
3. How to adjust the size of the search box of the native Launcher3 main interface?
Modifications are as follows:
Positioning /packages/apps/Launcher3/res/values/.
<dimen name="dynamic_grid_edge_margin">3dp</dimen>//Modify this to adjust the distance from the top of the search box.
<dimen name="dynamic_grid_search_bar_max_width">500dp</dimen>//The width of the search box is generally not required to be adjusted.
<dimen name="dynamic_grid_search_bar_height">48dp</dimen>//Do not adjust the height of the search box to 0. Delete the button to take up some space.
4. Let the main menu part applications be ranked first in the specified order?
Add res/values/: Applications that need to be sorted: The item content here must be filled in correctly, otherwise it will not match and cannot participate in the sorting.
<?xml version="1.0" encoding="utf-8"?> <resources> <string-array name="apps_componentName" translatable="false"> <item>ComponentInfo{/}</item> <item>ComponentInfo{/}</item> <item>ComponentInfo{/}</item> <item>ComponentInfo{.camera2/}</item> <item>ComponentInfo{/}</item> </string-array> </resources>
src/com/android/launcher3/
import ; import ; public static List<String> getAppsComponentName(final Context context) { return (().getStringArray(.apps_componentName)); } src/com/android/launcher3/ protected int mPreviousConfigMcc; static List<String> appArray = new ArrayList<String>(); LauncherModel(LauncherAppState app, IconCache iconCache, AppFilter appFilter) { ...... mUserManager = (context); appArray = (context); }
Add the following sortApps method: apps sort by , and based on the original sort, arrange the configured applications in the first order. The applications that are not involved in the original order.
public static final void sortApps(ArrayList<AppInfo> apps) { int length = (); List<AppInfo> assignApps = new ArrayList<AppInfo>(); for(int i=0;i<length;i++) { (i, null); } for(AppInfo app : apps){ for(int k=0; k<length; k++){ if (().equals((k))) { (k,app ); continue; } } } for (int i =length -1;i > -1 ;i--) { AppInfo app = (i); if(app != null){ (app); (0, app); } } (TAG ,"The Apps List after Sort!"); }
src/com/android/launcher3/
public void setApps(ArrayList<AppInfo> list) { if (!()) { ...... ().sortApps(mApps); (mApps);//On the original sorting, the configured applications are ranked first in order. updatePageCountsAndInvalidateData(); } } private void addAppsWithoutInvalidate(ArrayList<AppInfo> list) { ...... // SPRD: bug375932 2014-12-02 Feature customize app icon sort. ().sortApps(mApps); (mApps);//On the original sorting, the configured applications are ranked first in order.}
5. How to determine which default_workspace file is used in the standby HOME interface layout?
src/com/android/launcher3/
Select which default_workspace and the minWidthPx and minHeightPx in public DynamicGrid(Context context, Resources resources, int minWidthPx, int minHeightPx, int widthPx, int heightPx, int awPx, int ahPx) and the deviceProfiles list created in this method.
After the minWidthPx and minHeightPx values are converted to dpi, the deviceProfiles list is compared with it, and the default_workSpace of the deviceProfiles that is closest to the current screen size is selected as the default_workspace used by the final Home interface.
The detailed explanation is as follows:
src/com/android/launcher3/
① The deviceProfiles list is as follows:
(new DeviceProfile("Super Short Stubby", 255, 300, 2, 3, 48, 13, (hasAA ? 3 : 5), 48, .default_workspace_4x4)); (new DeviceProfile("Shorter Stubby", 255, 400, 3, 3, 48, 13, (hasAA ? 3 : 5), 48, .default_workspace_4x4)); (new DeviceProfile("Short Stubby", 275, 420, 3, 4, 48, 13, (hasAA ? 5 : 5), 48, .default_workspace_4x4)); (new DeviceProfile("Stubby", 255, 450, 3, 4, 48, 13, (hasAA ? 5 : 5), 48, .default_workspace_4x4)); (new DeviceProfile("Nexus S", 296, 491.33f, 4, 4, 48, 13, (hasAA ? 5 : 5), 48, .default_workspace_4x4)); (new DeviceProfile("Nexus 4", 335, 567, 4, 4, DEFAULT_ICON_SIZE_DP, 13, (hasAA ? 5 : 5), 56, .default_workspace_4x4)); (new DeviceProfile("Nexus 5", 359, 567, 4, 4, DEFAULT_ICON_SIZE_DP, 13, (hasAA ? 5 : 5), 56, .default_workspace_4x4)); (new DeviceProfile("Large Phone", 406, 694, 5, 5, 64, 14.4f, 5, 56, .default_workspace_5x5)); // The tablet profile is odd in that the landscape orientation // also includes the nav bar on the side (new DeviceProfile("Nexus 7", 575, 904, 5, 6, 72, 14.4f, 7, 60, .default_workspace_5x6)); // Larger tablet profiles always have system bars on the top & bottom (new DeviceProfile("Nexus 10", 727, 1207, 5, 6, 76, 14.4f, 7, 64, .default_workspace_5x6)); (new DeviceProfile("20-inch Tablet", 1527, 2527, 7, 7, 100, 20, 7, 72, .default_workspace_4x4));
② Recalculate the MinWidth and MinHeigh units are dpi.
mMinWidth = dpiFromPx(minWidthPx, dm); mMinHeight = dpiFromPx(minHeightPx, dm);
③ Create mProfile, which is the id of the default_workspace used in the final Home interface.
See which defaultLayoutId is default_workspace in mProfile.
mProfile = new DeviceProfile(context, deviceProfiles, mMinWidth, mMinHeight, widthPx, heightPx, awPx, ahPx, resources); src/com/android/launcher3/ DeviceProfile(Context context, ArrayList<DeviceProfile> profiles, float minWidth, float minHeight, int wPx, int hPx, int awPx, int ahPx, Resources res) {
In the method:
④ Points created with screen width and height (PointF xy = new PointF(width, height)
)anddeviceProfilesPoints created by w and h in (dimens = new PointF(widthDps, heightDps)
) Compare, that is, find the deviceProfiles closest to the current screen size from the deviceProfiles list.
DeviceProfile closestProfile = findClosestDeviceProfile(minWidth, minHeight, points); ......
⑤ Use default_workspace of deviceProfiles that is closest to the current screen size
defaultLayoutId = ;
6. How to replace the icon displayed on the launcher by a third-party application?
Modify in launcher/src/com/android/launcher3/
private CacheEntry cacheLocked(ComponentName componentName, ResolveInfo info, private CacheEntry cacheLocked(ComponentName componentName, ResolveInfo info, HashMap<Object, CharSequence> labelCache) { CacheEntry entry = (componentName); if (entry == null) { entry = new CacheEntry(); (componentName, entry); ComponentName key = (info); if (labelCache != null && (key)) { = (key).toString(); } else { = (mPackageManager).toString(); if (labelCache != null) { (key, ); } } if ( == null) { = ; } Drawable icon; int index = sysIndexOf(()); ("jxt", "index:"+index+",Name:"+()); icon = getFullResIcon(info); if (index >= 0) { = (icon, mContext); } else { = ( /* SPRD: Feature 253522, Remove the application drawer view @{ */ // getFullResIcon(info), mContext); icon, mContext, true); } /* Here is the replacement icon code {@*/ if("componentName for third-party applications".equals(())){ = ((), ); } /* @} */ } return entry; }
7. How to remove the boot boot page of Launcher3?
The modification plan is as follows:
Please locate the src/com/android/launcher3/ file:
class LauncherClings implements OnClickListener { ...... private static final String TAG_CROP_TOP_AND_SIDES = "crop_bg_top_and_sides private static final boolean DISABLE_CLINGS = false; private static final boolean DISABLE_CLINGS = true;
8. Why does Launcher3 display blurrier than the preview image after setting up some wallpapers?
During preview, there was no format conversion, so the display was normal!
When setting up wallpaper, the default is to convert in jpeg format, which leads to some loss after conversion. After setting up the wallpaper, some wallpapers with higher contrast will appear blurry!
Modify the plan:
The default modification is to convert in png format!
For versions before android6.0, please make the following modifications:
Files that are located to /packages/apps/Launcher3/
1. String mOutputFormat = "jpg";//Modify to "png"
2、
protected static String getFileExtension(String requestFormat) { String outputFormat = (requestFormat == null) ? "jpg"//Modify to "png" : requestFormat; outputFormat = (); return (("png") || ("gif")) ? "png" // We don't support gif compression. : "jpg"; }
For Android 6.0 version, please make the following modifications:
Navigate to /packages/apps/Launcher3/WallpaperPicker/src/com/android/gallery3d/common/file
if ((, DEFAULT_COMPRESS_QUALITY, tmpOut))
Modified to:
if ((, DEFAULT_COMPRESS_QUALITY, tmpOut))
9. What is the wallpaper path that comes with Launcher3 on the 6.0 platform?
In 6.0, the platform version presets some wallpaper resources, and the relevant paths are as follows:
The resource file is:
packages/apps/Launcher3/WallpaperPicker/res/drawable-xhdpi/
The string file is in:
packages/apps/Launcher3/WallpaperPicker/res/values-nodpi/
For more information about Android related content, please check out the topic of this site:Android development introduction and advanced tutorial》、《Android debugging skills and solutions to common problems》、《Android multimedia operation skills summary (audio, video, recording, etc.)》、《Summary of the usage of basic Android components》、《Android View View Tips Summary》、《Android layout layout tips summary"and"Android control usage summary》
I hope this article will be helpful to everyone's Android programming design.