Android系统:Launcher知识点总结

一:如何定制Launcher主菜单中应用程序图标的显示顺序?

请修改res/xml/default_toppackage.xml文件:

<toppackages xmlns:launcher="
http://schemas.android.com/apk/res/com.android.launcher2bird13gb">
<app
launcher:topPackageName="com.yahoo.mobile.client.android.odp"
launcher:topClassName="com.yahoo.mobile.client.android.odp.YahooODP"
launcher:topOrder="4"
/>
<app
launcher:topPackageName="com.yahoo.mobile.client.android.im"
launcher:topClassName="com.yahoo.mobile.client.android.im.YahooMessenger"
launcher:topOrder="5"
/>
<app
launcher:topPackageName="com.yahoo.mobile.client.android.mail"
launcher:topClassName=
"com.yahoo.mobile.client.android.mail.activity.YahooMail"
launcher:topOrder="6"
/>
<app
launcher:topPackageName="com.yahoo.mobile.client.android.news"
launcher:topClassName="com.yahoo.mobile.client.android.news.activity.Main"
launcher:topOrder="7"
/>
<app
launcher:topPackageName="com.yahoo.mobile.client.android.finance"
launcher:topClassName=
"com.yahoo.mobile.client.android.finance.activity.Main"
launcher:topOrder="10"
/>
</toppackages>

请按照上面的格式来编辑,编辑为特定app的topPackageName,topClassName以及order的值(从0开始)。
备注:如果是运营商项目,会有resource_overlay机制,请以resource_overlay路径下的default_toppackage.xml内
容为准。

二:如何去除Launcher默认的googlesearch bar?

M
请修改Launcher3/src/com/android/launcher3/Launcher.java的getOrCreateQsbBar()方法,直接return null。
L1:
请修改Launcher3/src/com/android/launcher3/Launcher.java的getQsbBar()方法,直接return null。

三:如果Launcher支持横屏显示,如何避免Launcher重新创建?

如果Launcher可以横屏显示,开机时有时会创建两次。有时用户从横屏应用退出回到Launcher时,Launcher也会重新创建。如何避免Launcher重新创建?
1. 请修改Launcher的AndroidManifest.xml,对Launcher这个Activity添加android:configChanges属性,在这个属性中设置Launcher感兴趣的config变化(例如orientation)。
2. 请在Launcher.java中覆写onConfigurationChanged方法,在此方法中处理Launcher感兴趣的config变化。

四:Launcher3如何让快捷方式默认创建在第一屏?

Launcher3在收到广播:com.android.launcher.action.INSTALL_SHORTCUT后,会自动在桌面上创建快捷方式,默认会创建在第二屏。如果让快捷方式默认创建在第一屏?
M:
请修改LauncherModel.java的findSpaceForItem方法,将如下代码:
int preferredScreenIndex = workspaceScreens.isEmpty() ? 0 : 1;
修改为:
int preferredScreenIndex =0;
L:
请修改LauncherModel.java的addAndBindAddedWorkspaceApps方法,将如下代码:
int startSearchPageIndex = workspaceScreens.isEmpty() ? 0 : 1;
修改为:
int startSearchPageIndex = 0;

五:Launcher3如何调整滑动灵敏度?

Launcher的桌面或者主菜单需要滑动比较长的距离或比较快的速度才会翻页,如何调整滑动灵敏度?
请修改Launcher3的PagedView.java中的变量:
private static final float SIGNIFICANT_MOVE_THRESHOLD = 0.4f;
请将这个变量变小。
备注:此修改L上会同时影响桌面和主菜单,M上只会影响桌面的滑动速度。

六:手机插SIM卡启动,Launcher会闪一下,如何避免?

手机插SIM卡启动,Launcher会闪一下,如何避免?
KK/L0/L1/M0:
1. 在AndroidManifest.xml中修改Launcher这个Activity的属性,加上android:configChanges="mcc|mnc"。
2. 在Launcher.java中增加如下方法:

@Override
public void onConfigurationChanged(Configuration newConfig) {
Log.d(TAG, "onConfigurationChanged() called.");
super.onConfigurationChanged(newConfig);
}
3. 在LauncherModel.java的onReceive方法中,找到action等于Intent.ACTION_CONFIGURATION_CHANGED的分支,注释
掉mcc/mnc变化时调用的forcereload()这行代码。

七:如何让Launcher3的主菜单和桌面支持循环滑动?

如何让Launcher3的主菜单和桌面支持循环滑动?
如果项目不是operator定制项目,请找到DefaultWorkspaceExt.java,将其中的supportAppListCycleSliding()返回值
修改为true。
如果项目是operator定制项目,请找到OP0XWorkspaceExt.java(例如移动是OP01WorkspaceExt.java),将其中的
supportAppListCycleSliding()返回值修改为true。
Note:从M0版本开始,Launcher主菜单的结构做了大的调整,从水平滑动更改为垂直滑动,所以无法再支持循环滑动。
按照以上修改后,只有Workspace可以支持循环滑动。

八:切换语言后返回Launcher主菜单,应用名称没有立即切换成正确的语言

1、进入Launcher出菜单,点击 设置>语言和输入法>语言,切换成其他语言;
2、点击back键回到Launcher主菜单,应用名称仍然是原来的语言,过几秒钟才切换成正确的语言。
1. 修改LauncherModel.java的getAppShortcutInfo方法,将其中的此段代码:
// from the db

if (TextUtils.isEmpty(info.title) && c != null) {
info.title = Utilities.trim(c.getString(titleIndex));
}
替换为:
// from PMS.
if (lai != null) {
info.title = lai.getLabel();
}
2. 修改IconCache.java的cacheLocked方法,在末尾添加:
if (info != null) {
entry.title = info.getLabel();
}

九:Launcher2的主菜单一直卡在加载状态,如何解决?

1、请修改Launcher.java的onDestroy方法,将如下code:
mModel.stopLoader();
app.setLauncher(null);
修改为:

// It's possible to receive onDestroy after a new Launcher activity has
// been created. In this case, don't interfere with the new Launcher.
if (mModel.isCurrentCallbacks(this)) {
mModel.stopLoader();
app.setLauncher(null);
}
2、请在LauncherModel.java中增加如下code

public boolean isCurrentCallbacks(Callbacks callbacks) {
  return (mCallbacks != null && mCallbacks.get() == callbacks);
}
十:如何动态打开Launcher的debug开关?

Launcher的deug开关有些默认是关闭的,譬如:DEBUG_MOTION。如何动态打开这些关闭的debug开关?
请执行
adb shell setprop launcher.debug.xxx true
adb shell stop
adb shell start
其中launcher.debug.xxx可以设置为下面的任意值:
launcher.debug.all
launcher.debug
launcher.debug.draw
launcher.debug.drag
launcher.debug.edit
launcher.debug.key
launcher.debug.layout
launcher.debug.loader
launcher.debug.motion
launcher.debug.performance
launcher.debug.surfacewidget
launcher.debug.unread
launcher.debug.loaders
launcher.debug.autotestcase
Note:此FAQ只支持KK2及以上版本,而且只对当次开机有效。

十一:桌面上特定的图标不能被移动和删除

桌面上有些预置的快捷方式,要求不能移动和删除,要怎么做?

1、请在Workspace.java的startDrag方法中判断将要拖动的图标是否是特定的图标
(通过package name/activity name判定),如果是的话,就禁止拖动。
2、那么如何获取当前点击图标的package name呢?
请在Workspace.java的startDrag方法中,在View child = cellInfo.cell;代码后面
添加:
ItemInfo info = (ItemInfo)cell.getTag();
接下来判断info是否是ShortcutInfo实例,如果是的话,就可以将info强制转换成
ShortcutInfo,然后拿到intent,最后通过intent获取package name/activity
name。

十二:快速双击home键回到Launcher3的桌面默认页

Launcher3桌面的默认页是首页(即0页)。
如果当前界面是Launcher3桌面的非默认页,点击home键,可以回到桌面的默认页。但是如果当前界面是其它应用,此
时快速双击home键却不能回到桌面的默认页。
请修改 Launcher3 的 launcher.java 的 onNewIntent 方法,将

final boolean alreadyOnHome = mHasFocus && ((intent.getFlags() &
Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
!= Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
修改为:
final boolean alreadyOnHome = (intent.getFlags() &
Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
!= Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT

十三:Launcher如何去掉进入应用时的动画效果?

点击Launcher桌面上的图标,会先有图标放大的动画,然后才进入应用。如何去掉动画效果?
请修改Launcher.java的startActivity方法,如下:

private boolean startActivity(View v, Intent intent, Object tag) {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try {
// Only launch using the new animation if the shortcut has not opted out (this is a
// private contract between launcher and may be ignored in the future).
//boolean useLaunchAnimation = (v != null) && //mtk modify
// !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION); //mtk modify
boolean useLaunchAnimation = false; //mtkadd
LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
UserManagerCompat userManager = UserManagerCompat.getInstance(this);

十四:Launcher AppWidget摆放不居中

如果Launcher的Workspace配置为非4x4大小,例如5x5。当摆放4x1或者其他AppWidget时不会居中。
上面描述的状况是无法避免的,任何桌面配置上总有一些AppWidget无法居中,例如4x4的桌面时3x3的也不能居中,反而在5x5的桌面上这个
AppWidget可以居中。
同时,也有些三方AppWidget会配置为5x1甚至6x1的状况,类似的兼容性问题是无法做到完美的,任何配置都有适配上的局限性。

十五:Launcher主菜单的搜索框匹配规则是什么?

从M版本开始,Launcher的主菜单上新增了一个搜索框,可以搜索主菜单中的应用。那么这个搜索框的匹配规则是什么呢?
搜索框的关键字会从主菜单应用名称中每个单词的开头开始匹配,无法从单词中间或者末尾匹配(空格隔开单词)。
譬如:在搜索框输入"T",可以匹配"Dev Tools"、"Sim Toolkit",无法匹配"Calculator"、"Contacts"。

十六:持续更新中...








评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值