PreviousArticleExplains how to modify the default interface settings for Android built-in launcher2 (http://www.cnblogs.com/mythou/p/3153880.html ).
Today, I am mainly talking about the settings of icons, la S, wallpapers, and so on in launcher. After all, we generally modify the launcher, which are all the places to be modified and easier to modify. Follow the instructions (in the previous article) to explain how to modify and analyze the logic involved.
For original blog posts, indicate the source:Http://www.cnblogs.com/mythou/p/3155692.html
1. Icon size and title size
The native Icon size of Android is set through the configuration file. The path of the configuration file is/RES/values/dimens. xml. Note that there are many folders corresponding to values, because they are supported by multiple languages. WhileDimens. XML is in the default values folder or values-land and values-port (for different resolutions and flat types, you need to find the corresponding dimens to modify according to your running situation. If you need to use multiple resolutions, it is recommended that all dimens be modified ). The following figure shows how to configure the workspace's button attributes. The following is an exampleThe cell size modified by values-land.
// edited by mythou
// http://www.cnblogs.com/mythou/
88dp
96dp
88dp
96dp
32dp
0dp
0dp
24dp
<! -- Folders -->
<Dimen name = "folder_preview_size"> 68dp </dimen>
<Dimen name = "folder_cell_width"> 86dp </dimen>
<Dimen name = "folder_cell_height"> 90dp </dimen>
<Dimen name = "folder_width_gap"> 3dp </dimen>
<Dimen name = "folder_height_gap"> 3dp </dimen>
<Dimen name = "folder_padding"> 6dp </dimen>
2. Add the Default background to the launcher icon.
The default Launcher icons are for their respective applications.ProgramThis also led to the feeling that the page icon looks a little messy and does not agree with the size. If the entire system is modified by yourself, you can set the uniform style of the built-in application icon. If it is a third-party program, it is difficult to guarantee, so a compromise is to add a background to all the icons, and The Style Looks consistent.
The launcher icon is obtained in the utilities. Java class. We can find the bitmap createiconbitmap (drawable icon, context) method. This method returns the application icon. The default createiconbitmap contains a method that adds a colorful background, but it is blocked. We can refer to this method to add a default background image.
// Edited by mythou
//Http://www.cnblogs.com/mythou/
Static Bitmap createiconbitmap (drawable icon, context ){ // ............... Final Int Left = (texturewidth-width )/ 2 ; Final Int Top = (textureheight-height )/ 2 ; // For testing, add a colored background border If ( False ){ // Draw a big box for the icon for debugging Canvas. drawcolor (scolors [scolorindex]); If (++ Scolorindex> = scolors. Length) scolorindex = 0 ; Paint debugpaint = New Paint (); debugpaint. setcolor ( 0xffcccc00 ); Canvas. drawrect (left, top, left + Width, top + Height, debugpaint );} // Add the icon background image Owl If ( True ) {Bitmap backbitmap = Bitmapfactory. decoderesource (context. getresources (), R. drawable. apical_icon_bg ); Int Backwidth = Backbitmap. getwidth (); Int Backheight = Backbitmap. getheight (); If (Backwidth! = Siconwidth | backheight! = Siconheight) {matrix Matrix =New Matrix (); matrix. postscale (( Float ) Siconwidth/backwidth ,( Float ) Siconheight/ Backheight); canvas. drawbitmap (bitmap. createbitmap (backbitmap, 0 , 0 , Backwidth, backheight, matrix, True ), 0.0f , 0.0f , Null );} Else {Canvas. drawbitmap (backbitmap, 0.0f , 0.0f , Null );}} //................ Return Bitmap ;}}
AboveCode, Added a default background image of R. drawable. apical_icon_bg as the background, so that all the icons look the same size. And the style is similar. The user experience is better for system applications. If you need some nice effects, you can use the icon here for reflection or other effects.
3. Change the default wallpaper of launcher.
Launcher's default wallpaper configuration is configured under Res under the Framework, and images are also placed under the framework. For projects that require independent launcher, it is inconvenient to leave the framework. Therefore, the launcher implements a default wallpaper setting function. Default wallpaper, which must be displayed only when launcher runs for the first time or restores the default settings.
Therefore, I set the default wallpaper to showfirstrunworkspacecling () under the oncreate () method of the launcher. Java class for execution.
Showfirstrunworkspacecling () method. Only launcher starts or clears data for the first time and restores the settings. . Call the following method in showfirstrunworkspacecling ().
// Edited by mythou
//Http://www.cnblogs.com/mythou/
Private Void Setdefaultwallpaper (){ // Modify the Default background owl test. You can replace the default static graph default_wallpaper in the framework. Wallpapermanager mwallpaermanager; mwallpaermanager = Wallpapermanager. getinstance ( This ); Try {Mwallpaermanager. setresource (R. drawable. launcher_default_bg );} Catch (Ioexception e) {log. E (tag, " Set Default wallpaper Error " ); E. printstacktrace ();}}
Launcher's wallpapers call the system wallpapermanager. For more information, see the source code.
Android static wallpaper. The default value is frameworks/base/CORE/RES/drawable/default_wallpaper.jpg. If it is a system, you can replace this jpg image or use the default wallpaper replacement function.
For the default live wallpaper, modify/framework/base/CORE/RES/values/config. xml.
<StringName ="Default_wallpaper_component"> @ Null </String>//Change null to a specific program name, as shown below:<StringName ="Default_wallpaper_component"Translatable ="False"> Package name/dynamic wallpaper service name </String>
In addition, launcher comes with some default wallpapers. In the Res/drawable folder of launcher, the sizes of folders in different resolutions are different.
These default wallpapers are configured in values/wallpapers. xml under launcher.
// Edited by mythou
//Http://www.cnblogs.com/mythou/
string -array name =
"
wallpapers
" translatable =
"
false
"
wallpaper_01
wallpaper_02
wallpaper_03
wallpaper_04
wallpaper_05
wallpaper_06
wallpaper_07
wallpaper_08
wallpaper_09
wallpaper_10
wallpaper_11
wallpaper_12
string
-array>
However, the system supports up to 24 images by default. You can modify the wallpaper name or add a new wallpaper. The wallpaper name corresponds to the image name one by one.
4. wallpaper setting process:
The specific wallpaper operations are actually implemented in the fragment of wallpaperchooserdialogfragment,
Find the default Wallpaper:
// Edited by mythou
//Http://www.cnblogs.com/mythou/
Private Void Findwallpapers () {mthumbs = New Arraylist <integer> (24 ); Mimages = New Arraylist <integer> ( 24 ); Final resources Resources = Getresources (); // Context. getpackagename () may return the "original" package name, // Com. Android. launcher2; resources needs the real package name, // Com. Android. launcher. So we ask resources for what it thinks // Package name shocould be. Final string packagename = Resources. getresourcepackagename (R. array. wallpapers); addwallpapers (resources, packagename, R. array. wallpapers); addwallpapers (resources, packagename, R. array. extra_wallpapers );}
Here, R. array. wallpapers is the xml configuration file of the default wallpaper name mentioned above. Load all default wallpapers using this file. In addition to wallpapers, there is also an extra_wallpapers. The two functions work the same way.
Setting wallpapers is simple, just like setting default wallpapers
// Edited by mythou
//Http://www.cnblogs.com/mythou/
Private Void Selectwallpaper (Int Position ){ Try {Wallpapermanager wpm = (Wallpapermanager) getactivity (). getsystemservice (context. wallpaper_service); wpm. setresource (mimages. Get (Position ));// Set the wallpaperActivity = Getactivity (); activity. setresult (activity. result_ OK); activity. Finish ();} Catch (Ioexception e) {log. E (tag, " Failed to set Wallpaper: " + E );}}
Call the setresource method of wallpapermanager.
I will write it here today. If any error is found, please leave a message. Thank you!