Android Launcer3 如何去除桌面欢迎页面或引导页面

思路

  1. 查找欢迎页面中的文字或图片对应的资源
  2. 查找资源对应在代码中的位置
  3. 查找对应代码所在的函数
  4. 分析函数逻辑

分析步骤

  1. 查找欢迎页面中的文字或图片对应的资源

关键字:

<string name="first_run_cling_title" msgid="2459738000155917941">"欢迎使用"</string>

关键字所在地址:

./res/layout/longpress_cling_welcome_content.xml:   android:text="@string/first_run_cling_title"
  1. 查找资源对应在代码中的位置

搜索关键字 “longpress_cling_welcome_content

./src/com/android/launcher3/LauncherClings.java:        mInflater.inflate(showWelcome ? R.layout.longpress_cling_welcome_content
  1. 查找对应代码所在的函数

根据2可以得知LauncherClings.java 中的 showLongPressCling 函数是主要位置

    public void showLongPressCling(boolean showWelcome) {
       ......

        final ViewGroup content = (ViewGroup) cling.findViewById(R.id.cling_content);
        mInflater.inflate(showWelcome ? R.layout.longpress_cling_welcome_content
                : R.layout.longpress_cling_content, content); //TODO 欢迎页加载
        content.findViewById(R.id.cling_dismiss_longpress_info).setOnClickListener(this);

        if (TAG_CROP_TOP_AND_SIDES.equals(content.getTag())) {
            Drawable bg = new BorderCropDrawable(mLauncher.getResources().getDrawable(R.drawable.cling_bg),
                    true, true, true, false);
            content.setBackground(bg);
        }

        root.addView(cling);

        if (showWelcome) {
            // This is the first cling being shown. No need to animate.
            return;
        }

        // Animate
        ......
    }
  1. 分析函数逻辑

那么如何修改去掉让欢迎页呢?

在Launcher.java 初始化中搜索 showLongPressCling这个函数的调用
1、在onCreate()中

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        ......
        //*/ 注释这部分代码块 @{
        if (shouldShowIntroScreen()) {
            showIntroScreen();
        } else {
            showFirstRunActivity();
            showFirstRunClings(); //第一步
        }
        //*/ @}
    }

2、调用showFirstRunClings()

    @Thunk void showFirstRunClings() {
        // The two first run cling paths are mutually exclusive, if the launcher is preinstalled
        // on the device, then we always show the first run cling experience (or if there is no
        // launcher2). Otherwise, we prompt the user upon started for migration
        LauncherClings launcherClings = new LauncherClings(this);
        if (launcherClings.shouldShowFirstRunOrMigrationClings()) {
            mClings = launcherClings;
            if (mModel.canMigrateFromOldLauncherDb(this)) {
                launcherClings.showMigrationCling();
            } else {
                launcherClings.showLongPressCling(true); //第二步
            }
        }
    }

3、 去掉代码中注释部分即可实现去掉欢迎界面

扩展

如何使用ADB去掉欢迎页?

我们继续追踪代码逻辑,在 showFirstRunClings() 函数中,有一个判断决定是否弹出欢迎页面或引导页面
if (launcherClings.shouldShowFirstRunOrMigrationClings())

我们接着看 shouldShowFirstRunOrMigrationClings 这个函数

private static final String MIGRATION_CLING_DISMISSED_KEY = "cling_gel.migration.dismissed";
private static final String WORKSPACE_CLING_DISMISSED_KEY = "cling_gel.workspace.dismissed";

public boolean shouldShowFirstRunOrMigrationClings() {
    SharedPreferences sharedPrefs = mLauncher.getSharedPrefs();
    return areClingsEnabled() &&
        !sharedPrefs.getBoolean(WORKSPACE_CLING_DISMISSED_KEY, false) &&
        !sharedPrefs.getBoolean(MIGRATION_CLING_DISMISSED_KEY, false);
}

从如上代码可以看出 return 的值受到 两个 sharedpreferences 值的影响,只需要修改默认值,就可以
控制逻辑的判断,从而关闭页面。

去除Launcher3 开机欢迎页,修改 SharedPreferences :

地址:/data/data/com.android.launcher3/shared_prefs/com.android.launcher3.prefs.xml

步骤:
@1.
添加一条 <boolean name="cling_gel.workspace.dismissed" value="true" /> 到xml文件中

@2.
adb push C:\Users\Administrator\com.android.launcher3.prefs.xml /data/data/com.android.launcher3/shared_prefs/

@3.
adb reboot

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值