Launcher3仿小米桌面

剛開始弄這個的時候 沒有一點頭緒 ,後來看到4.4 跟5.1的源碼有這個方法 ,剛開始嘗試是把4.4的Launcher移植到6.0版本,編譯報錯,版本差別太大了。之後拿到5.1的源碼嘗試編譯 通過了,然後就開始分析
首先找到控制所有應用按鈕顯示的地方在com\android\launcher3\LauncherAppState.java

    public static boolean isDisableAllApps() {
        // Returns false on non-dogfood builds.
        /*註釋下面的兩句 直接返回true*/
        //return getInstance().mBuildInfo.isDogfoodBuild() &&
               // Utilities.isPropertyEnabled(Launcher.DISABLE_ALL_APPS_PROPERTY);
        return true;
    }

這樣按鈕就消失了了,所有的app都出現再 workspace
只修改此處 還有兩個大坑,一、通過上面的步驟的話 我們默認是把所有應用顯示在了workspace上,然而用系統launcher的人都知道在workspace上默認只有移除動作的如下
這裏寫圖片描述
只有在主菜單長按應用纔會出現卸載或應用信息按鈕 在workspace已出只是把圖標刪除了,進入到設置–》應用裏面還能找到apk
如果adb shell pm clear com.android.launcher3重啓Launcher app又出現在桌面上
這個坑請參考此博客 android launcher 之踩到的坑
下面說 第二個坑 修改之後 長按桌面空白處 點擊進入wight界面會出現異常 進去wight界面之後 返回 不到主界面了 點返回鍵 home鍵都沒用 要長按一下桌面 再點一下桌面纔會回來
找到在Launcher.java的兩個方法showAppsCustomizeHelper和hideAppsCustomizeHelper中用到

/**
     * Sets the all apps button. This method is called from {@link Hotseat}.
     */
    public void setAllAppsButton(View allAppsButton) {
        mAllAppsButton = allAppsButton;
    }

    public View getAllAppsButton() {
        return mAllAppsButton;
    }
 // If for some reason our views aren't initialized, don't animate
       boolean initialized = getAllAppsButton() != null;

        if (animated && initialized*) {
        ...
        }

原因是去主菜單後 這個mAllAppsButton是空的,就出現異常了
我就用getHotseat()替換getAllAppsButton()方法 完美解決

 // If for some reason our views aren't initialized, don't animate
        boolean initialized = getHotseat() != null;

        if (animated &&initialized) {
            mStateAnimation = LauncherAnimUtils.createAnimatorSet();
            if (workspaceAnim != null) {
                mStateAnimation.play(workspaceAnim);
            }

兩個方法showAppsCustomizeHelper和hideAppsCustomizeHelper中用到的都要替換
這裏寫圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章