Android開(kāi)發(fā)中Launcher3常見(jiàn)默認(rèn)配置修改方法總結(jié)
本文實(shí)例講述了Android開(kāi)發(fā)中Launcher3常見(jiàn)默認(rèn)配置修改方法。分享給大家供大家參考,具體如下:
Launcher概述
Launcher是開(kāi)機(jī)完成后第一個(gè)啟動(dòng)的應(yīng)用,用來(lái)展示應(yīng)用列表和快捷方式、小部件等。Launcher作為第一個(gè)(開(kāi)機(jī)后第一個(gè)啟動(dòng)的應(yīng)用)展示給用戶的應(yīng)用程序,其設(shè)計(jì)的好壞影響到用戶的體驗(yàn),甚至影響用戶購(gòu)機(jī)的判斷。所以很多品牌廠商都會(huì)不遺余力的對(duì)Launcher進(jìn)行深度定制,如小米的MIUI、華為的EMUI等。Android默認(rèn)的Launcher沒(méi)有過(guò)多的定制,更加簡(jiǎn)潔,受到源生黨的追捧,Google的Nexus系列手機(jī)基本都是用的源生Launcher,目前Android源生的Launcher版本是Launcher3,后面的相關(guān)內(nèi)容也都是以Launcher3為基礎(chǔ)。
Launcher3默認(rèn)配置修改
1.如何設(shè)置默認(rèn)頁(yè)
res/values/Config.xml
<integer name="config_workspaceDefaultScreen">0</integer>
在Launcher3 桌面,不管在哪一頁(yè),按HOME 鍵,會(huì)回到默認(rèn)頁(yè)。
2.如何隱藏launcher3中的搜索框
① 在Launcher3/src/com/android/launcher3/Launcher.java中
注釋updateGlobalIcons()方法調(diào)用,共兩處。
public View getQsbBar() {
if (mQsbBar == null) {
mQsbBar = mInflater.inflate(R.layout.search_bar, mSearchDropTargetBar, false);
- mSearchDropTargetBar.addView(mQsbBar);
}
+ mQsbBar.setVisibility(View.GONE);
return mQsbBar;
}
@Override
public void bindSearchablesChanged() { //注釋該方法內(nèi)容
/* boolean searchVisible = updateGlobalSearchIcon();
boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
if (mSearchDropTargetBar != null) {
mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
}
*/
}
② 在Launcher3/src/com/android/launcher3/DynamicGrid.java中
// Layout the search bar //注釋如下內(nèi)容 /* View qsbBar = launcher.getQsbBar(); LayoutParams vglp = qsbBar.getLayoutParams(); vglp.width = LayoutParams.MATCH_PARENT; vglp.height = LayoutParams.MATCH_PARENT; qsbBar.setLayoutParams(vglp); */
③ 在Launcher3/res/values/dimens.xml中
- <dimen name="dynamic_grid_search_bar_height">48dp</dimen>
+ <dimen name="dynamic_grid_search_bar_height">18dp</dimen>
重新編譯后即可看到效果。
3.如何調(diào)整原生Launcher3主界面的search框的大?。?/p>
修改如下:
定位打/packages/apps/Launcher3/res/values/dimens.xml。
<dimen name="dynamic_grid_edge_margin">3dp</dimen>//修改這個(gè)可以調(diào)整search框距離頂部距離。
<dimen name="dynamic_grid_search_bar_max_width">500dp</dimen>//search框的寬度,一般不需要調(diào)整。
<dimen name="dynamic_grid_search_bar_height">48dp</dimen>//search框的高度,不要調(diào)整為0,刪除按鈕需要占用一部分空間。
4.讓主菜單部分應(yīng)用按指定順序排在前面?
添加res/values/arrays.xml:需要排序的應(yīng)用:這里的item 內(nèi)容一定要填寫(xiě)正確,否則會(huì)匹配不上,無(wú)法參與排序。
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="apps_componentName" translatable="false">
<item>ComponentInfo{com.android.vending/com.android.vending.AssetBrowserActivity}</item>
<item>ComponentInfo{com.android.browser/com.android.browser.BrowserActivity}</item>
<item>ComponentInfo{com.android.settings/com.android.settings.Settings}</item>
<item>ComponentInfo{com.android.camera2/com.android.camera.CameraLauncher}</item>
<item>ComponentInfo{com.android.mms/com.android.mms.ui.ConversationList}</item>
</string-array>
</resources>
src/com/android/launcher3/Utilities.java
import java.util.Arrays;
import java.util.List;
public static List<String> getAppsComponentName(final Context context) {
return Arrays.asList(context.getResources().getStringArray(R.array.apps_componentName));
}
src/com/android/launcher3/LauncherModel.java
protected int mPreviousConfigMcc;
static List<String> appArray = new ArrayList<String>();
LauncherModel(LauncherAppState app, IconCache iconCache, AppFilter appFilter) {
......
mUserManager = UserManagerCompat.getInstance(context);
appArray = Utilities.getAppsComponentName(context);
}
添加如下sortApps 方法:apps 按arrays.xml 排序,在原來(lái)的排序基礎(chǔ)上,將arrays.xml 配置的應(yīng)用按順序排在前面。arrays.xml中沒(méi)有涉及到的應(yīng)用,還是原來(lái)的順序。
public static final void sortApps(ArrayList<AppInfo> apps) {
int length = appArray.size();
List<AppInfo> assignApps = new ArrayList<AppInfo>();
for(int i=0;i<length;i++) {
assignApps.add(i, null);
}
for(AppInfo app : apps){
for(int k=0; k<length; k++){
if (app.componentName.toString().equals(appArray.get(k))) {
assignApps.set(k,app );
continue;
}
}
}
for (int i =length -1;i > -1 ;i--) {
AppInfo app = assignApps.get(i);
if(app != null){
apps.remove(app);
apps.add(0, app);
}
}
Log.d(TAG ,"The Apps List after Sort!");
}
src/com/android/launcher3/AppsCustomizePagedView.java
public void setApps(ArrayList<AppInfo> list) {
if (!LauncherAppState.isDisableAllApps()) {
......
SprdAppSortAddonStub.getInstance().sortApps(mApps);
LauncherModel.sortApps(mApps);//在原來(lái)排序的基礎(chǔ)上,再將arrays.xml中配置的應(yīng)用按順序排在前面。
updatePageCountsAndInvalidateData();
}
}
private void addAppsWithoutInvalidate(ArrayList<AppInfo> list) {
......
// SPRD: bug375932 2014-12-02 Feature customize app icon sort.
SprdAppSortAddonStub.getInstance().sortApps(mApps);
LauncherModel.sortApps(mApps);//在原來(lái)排序的基礎(chǔ)上,再將arrays.xml中配置的應(yīng)用按順序排在前面。
}
5.如何確定待機(jī)HOME界面布局使用的是哪個(gè)default_workspace文件?
src/com/android/launcher3/DynamicGrid.java
選擇哪個(gè)default_workspace 和public DynamicGrid(Context context, Resources resources,int minWidthPx, int minHeightPx, int widthPx, int heightPx, int awPx, int ahPx)中的minWidthPx 和minHeightPx 以及該方法中創(chuàng)建的deviceProfiles 列表關(guān)。
minWidthPx 、minHeightPx 值轉(zhuǎn)換為dpi之后 ,deviceProfiles 列表與其進(jìn)行比較,選擇與當(dāng)前屏幕大小最接近的deviceProfiles 的default_workSpace作為最終Home界面使用的default_workspace。
詳細(xì)解釋如下:
src/com/android/launcher3/DynamicGrid.java中
① deviceProfiles 列表如下:
deviceProfiles.add(new DeviceProfile("Super Short Stubby",
255, 300, 2, 3, 48, 13, (hasAA ? 3 : 5), 48, R.xml.default_workspace_4x4));
deviceProfiles.add(new DeviceProfile("Shorter Stubby",
255, 400, 3, 3, 48, 13, (hasAA ? 3 : 5), 48, R.xml.default_workspace_4x4));
deviceProfiles.add(new DeviceProfile("Short Stubby",
275, 420, 3, 4, 48, 13, (hasAA ? 5 : 5), 48, R.xml.default_workspace_4x4));
deviceProfiles.add(new DeviceProfile("Stubby",
255, 450, 3, 4, 48, 13, (hasAA ? 5 : 5), 48, R.xml.default_workspace_4x4));
deviceProfiles.add(new DeviceProfile("Nexus S",
296, 491.33f, 4, 4, 48, 13, (hasAA ? 5 : 5), 48, R.xml.default_workspace_4x4));
deviceProfiles.add(new DeviceProfile("Nexus 4",
335, 567, 4, 4, DEFAULT_ICON_SIZE_DP, 13, (hasAA ? 5 : 5), 56, R.xml.default_workspace_4x4));
deviceProfiles.add(new DeviceProfile("Nexus 5",
359, 567, 4, 4, DEFAULT_ICON_SIZE_DP, 13, (hasAA ? 5 : 5), 56, R.xml.default_workspace_4x4));
deviceProfiles.add(new DeviceProfile("Large Phone",
406, 694, 5, 5, 64, 14.4f, 5, 56, R.xml.default_workspace_5x5));
// The tablet profile is odd in that the landscape orientation
// also includes the nav bar on the side
deviceProfiles.add(new DeviceProfile("Nexus 7",
575, 904, 5, 6, 72, 14.4f, 7, 60, R.xml.default_workspace_5x6));
// Larger tablet profiles always have system bars on the top & bottom
deviceProfiles.add(new DeviceProfile("Nexus 10",
727, 1207, 5, 6, 76, 14.4f, 7, 64, R.xml.default_workspace_5x6));
deviceProfiles.add(new DeviceProfile("20-inch Tablet",
1527, 2527, 7, 7, 100, 20, 7, 72, R.xml.default_workspace_4x4));
② 重新計(jì)算MinWidth 和MinHeigh 單位是dpi。
mMinWidth = dpiFromPx(minWidthPx, dm); mMinHeight = dpiFromPx(minHeightPx, dm);
③ 創(chuàng)建mProfile,mProfile.defaultLayoutId 就是最終Home界面使用的default_workspace 的id。
mProfile中的defaultLayoutId 是哪個(gè)default_workspace 見(jiàn)DeviceProfile.java。
mProfile = new DeviceProfile(context, deviceProfiles,
mMinWidth, mMinHeight,
widthPx, heightPx,
awPx, ahPx,
resources);
src/com/android/launcher3/DeviceProfile.java
DeviceProfile(Context context,
ArrayList<DeviceProfile> profiles,
float minWidth, float minHeight,
int wPx, int hPx,
int awPx, int ahPx,
Resources res) {
方法中:
④ 用屏幕寬高創(chuàng)建的點(diǎn)(PointF xy = new PointF(width, height))與 deviceProfiles中的w 和 h 創(chuàng)建的點(diǎn)(dimens = new PointF(widthDps, heightDps))進(jìn)行比較,也就是從deviceProfiles 列表中找出和當(dāng)前屏幕大小最接近的deviceProfiles。
DeviceProfile closestProfile = findClosestDeviceProfile(minWidth, minHeight, points); ......
⑤ 采用和當(dāng)前屏幕大小最接近的deviceProfiles的default_workspace
defaultLayoutId = closestProfile.defaultLayoutId;
6.如何替換第三方應(yīng)用在launcher上顯示的圖標(biāo)?
在launcher/src/com/android/launcher3/IconCache.java中修改,
private CacheEntry cacheLocked(ComponentName componentName, ResolveInfo info, private CacheEntry cacheLocked(ComponentName componentName, ResolveInfo info,
HashMap<Object, CharSequence> labelCache) {
CacheEntry entry = mCache.get(componentName);
if (entry == null) {
entry = new CacheEntry();
mCache.put(componentName, entry);
ComponentName key = LauncherModel.getComponentNameFromResolveInfo(info);
if (labelCache != null && labelCache.containsKey(key)) {
entry.title = labelCache.get(key).toString();
} else {
entry.title = info.loadLabel(mPackageManager).toString();
if (labelCache != null) {
labelCache.put(key, entry.title);
}
}
if (entry.title == null) {
entry.title = info.activityInfo.name;
}
Drawable icon;
int index = sysIndexOf(componentName.getClassName());
Log.i("jxt", "index:"+index+",Name:"+componentName.getClassName());
icon = getFullResIcon(info);
if (index >= 0) {
entry.icon = Utilities.createIconBitmap(icon, mContext);
} else {
entry.icon = Utilities.createIconBitmap(
/* SPRD: Feature 253522, Remove the application drawer view @{ */
// getFullResIcon(info), mContext);
icon, mContext, true);
}
/* 此處即為替換圖標(biāo)代碼 {@*/
if("第三方應(yīng)用的componentName".equals(componentName.toString())){
entry.icon = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.xxx);
}
/* @} */
}
return entry;
}
7.如何去掉Launcher3的開(kāi)機(jī)引導(dǎo)頁(yè)面?
修改方案如下:
請(qǐng)定位到src/com/android/launcher3/LauncherClings.java文件:
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.為何Launcher3設(shè)置一些壁紙后,壁紙顯示比預(yù)覽圖模糊?
預(yù)覽的時(shí)候,沒(méi)有做格式轉(zhuǎn)化,所以顯示正常!
在設(shè)置壁紙的時(shí)候,默認(rèn)是采用jpeg格式轉(zhuǎn)換的,導(dǎo)致轉(zhuǎn)換后損耗了一些,設(shè)置壁紙后,某些對(duì)比度比較高的壁紙就顯示的模糊!
修改方案:
默認(rèn)修改為采用png格式轉(zhuǎn)換!
android6.0之前的版本,請(qǐng)做如下修改:
定位到/packages/apps/Launcher3/的WallpaperCropActivity.java文件
1、String mOutputFormat = "jpg";//修改為"png"
2、
protected static String getFileExtension(String requestFormat) {
String outputFormat = (requestFormat == null)
? "jpg"http://修改為"png"
: requestFormat;
outputFormat = outputFormat.toLowerCase();
return (outputFormat.equals("png") || outputFormat.equals("gif"))
? "png" // We don't support gif compression.
: "jpg";
}
android6.0的版本,請(qǐng)做如下修改:
定位到/packages/apps/Launcher3/WallpaperPicker/src/com/android/gallery3d/common/BitmapCropTask.java文件
if (crop.compress(CompressFormat.JPEG, DEFAULT_COMPRESS_QUALITY, tmpOut))
修改為:
if (crop.compress(CompressFormat.PNG, DEFAULT_COMPRESS_QUALITY, tmpOut))
9. 6.0平臺(tái)上Launcher3自帶的壁紙路徑是什么?
在6.0中,平臺(tái)版本預(yù)置了一些壁紙資源,相關(guān)路徑如下:
資源文件在:
packages/apps/Launcher3/WallpaperPicker/res/drawable-xhdpi/
字串文件在:
packages/apps/Launcher3/WallpaperPicker/res/values-nodpi/wallpapers.xml
更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android開(kāi)發(fā)入門(mén)與進(jìn)階教程》、《Android調(diào)試技巧與常見(jiàn)問(wèn)題解決方法匯總》、《Android多媒體操作技巧匯總(音頻,視頻,錄音等)》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)》
希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。
- 適配android7.0獲取文件的Uri的方法
- Android7.0 工具類:DiffUtil詳解
- Android7.0 MessageQueue詳解
- Android7.0上某些PopuWindow出現(xiàn)顯示位置不正確問(wèn)題的解決方法
- Android開(kāi)發(fā)實(shí)現(xiàn)Launcher3應(yīng)用列表修改透明背景的方法
- Android launcher中模擬按home鍵的實(shí)現(xiàn)
- Android6.0 Launcher2應(yīng)用解析
- Android的Launcher啟動(dòng)器中添加快捷方式及小部件實(shí)例
- Android實(shí)現(xiàn)向Launcher添加快捷方式的方法
- Android7.0開(kāi)發(fā)實(shí)現(xiàn)Launcher3去掉應(yīng)用抽屜的方法詳解
相關(guān)文章
詳解Android開(kāi)發(fā)技巧之PagerAdapter實(shí)現(xiàn)類的封裝
這篇文章主要介紹了詳解Android開(kāi)發(fā)技巧之PagerAdapter實(shí)現(xiàn)類的封裝,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-11-11
Android 多國(guó)語(yǔ)言value文件夾命名的方法
這篇文章主要介紹了Android 多國(guó)語(yǔ)言value文件夾命名的方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-03-03
Android編程實(shí)現(xiàn)調(diào)用系統(tǒng)圖庫(kù)與裁剪圖片功能
這篇文章主要介紹了Android編程實(shí)現(xiàn)調(diào)用系統(tǒng)圖庫(kù)與裁剪圖片功能,結(jié)合實(shí)例形式分析了Android針對(duì)圖形的旋轉(zhuǎn)與剪切等具體操作技巧,需要的朋友可以參考下2017-01-01
Android中CountDownTimer 實(shí)現(xiàn)倒計(jì)時(shí)功能
本篇文章主要介紹了Android中CountDownTimer 實(shí)現(xiàn)倒計(jì)時(shí)功能,CountDownTimer 是android 自帶的一個(gè)倒計(jì)時(shí)類,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-05-05
一次OOM問(wèn)題排查過(guò)程實(shí)戰(zhàn)記錄
這篇文章主要給大家介紹了一次OOM問(wèn)題排查過(guò)程,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-05-05
Android 使用自定義RecyclerView控件實(shí)現(xiàn)Gallery效果
這篇文章主要介紹了Android 使用自定義RecyclerView 實(shí)現(xiàn)Gallery效果,本文給大家簡(jiǎn)單介紹了RecyclerView的基本用法,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-10-10
Android中判斷有無(wú)可用網(wǎng)絡(luò)的代碼(是否是3G或者WIFI網(wǎng)絡(luò))
在android開(kāi)發(fā)中經(jīng)常會(huì)遇到的判斷有無(wú)可用網(wǎng)絡(luò)的代碼,防止客戶流量損失2013-01-01
Android系統(tǒng)中的藍(lán)牙連接程序編寫(xiě)實(shí)例教程
這篇文章主要介紹了Android系統(tǒng)中的藍(lán)牙連接程序編寫(xiě)實(shí)例教程,包括藍(lán)牙的設(shè)備查找及自動(dòng)配對(duì)等各種基礎(chǔ)功能的實(shí)現(xiàn),十分給力,需要的朋友可以參考下2016-04-04
自己實(shí)現(xiàn)的android樹(shù)控件treeview
在項(xiàng)目中經(jīng)常需要一個(gè)需要一個(gè)樹(shù)狀框架,因?yàn)橐恍┰驔](méi)有使用系統(tǒng)自帶的控件,所以就自己寫(xiě)了一個(gè),現(xiàn)在分享給大家2014-01-01

