当前位置:首页 » 《随便一记》 » 正文

Android Launcher 在底部导航栏添加一个“☰”按钮,点击弹出全部应用_王睿丶的博客

20 人参与  2022年04月19日 16:32  分类 : 《随便一记》  评论

点击全文阅读


相关文件
frameworks/base/packages/SystemUI/res/layout/all_app.xml
frameworks/base/packages/SystemUI/res/values-sw400dp/config.xml
frameworks/base/packages/SystemUI/res/values-sw600dp/config.xml
frameworks/base/packages/SystemUI/res/values-sw720dp/config.xml
frameworks/base/packages/SystemUI/res/values-sw900dp/config.xml
frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java
frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarInflaterView.java
frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java
packages / apps/Launcher3/src/com/android/launcher3/Launcher.java

思路

  • 1、 创建allApp布局
  • 2、 控制导航键显示位置
  • 3、 在Java代码中拿到它的xml资源文件
  • 4、 在Java代码中设置allApp图标
  • 5、 给allApp设置监听事件
  • 6、 实现弹出全部应用

实现

  • 第一步:创建allApp布局
    frameworks/base/packages/SystemUI/res/layout/all_app.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2016 The Android Open Source Project
     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at
          http://www.apache.org/licenses/LICENSE-2.0
     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<com.android.systemui.statusbar.policy.KeyButtonView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:systemui="http://schemas.android.com/apk/res-auto"
    android:id="@+id/all_app"
    android:layout_width="@dimen/navigation_key_width"
    android:layout_height="match_parent"
    android:layout_weight="0"
    android:scaleType="center"
    android:contentDescription="@string/accessibility_home"
    android:paddingStart="@dimen/navigation_key_padding"
    android:paddingEnd="@dimen/navigation_key_padding"
    />
  • 第二步:控制导航键显示位置
    frameworks/base/packages/SystemUI/res/values-sw400dp/config.xml
    frameworks/base/packages/SystemUI/res/values-sw600dp/config.xml
    frameworks/base/packages/SystemUI/res/values-sw720dp/config.xml
    frameworks/base/packages/SystemUI/res/values-sw900dp/config.xml
<resources>
    <!-- Nav bar button default ordering/layout -->
    <string name="config_navBarLayout" translatable="false">all_app;back,home,recent;right</string>
</resources>
  • 第三步:在Java代码中拿到它的xml资源文件
    frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarInflaterView.java
public static final String ALL_APP = "all_app";    //声明
private View createView(String buttonSpec, ViewGroup parent, LayoutInflater inflater) {
        if (HOME.equals(button)) {
            v = inflater.inflate(R.layout.home, parent, false);
        } else if(ALL_APP.equals(button)) {
            v = inflater.inflate(R.layout.all_app, parent, false);  /* 获取布局 */
        } else if (BACK.equals(button)) {
            v = inflater.inflate(R.layout.back, parent, false);
        } 
} 
  • 第四步:在Java代码中设置allApp图标
    frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java
  private KeyButtonDrawable mAllAppIcon;      /* 创建图标对象 */
 public NavigationBarView(Context context, AttributeSet attrs) {
  /* 添加allApp给mButtonDispatchers */
        mButtonDispatchers.put(R.id.all_app, new ButtonDispatcher(R.id.all_app));
        mButtonDispatchers.put(R.id.back, new ButtonDispatcher(R.id.back));
        mButtonDispatchers.put(R.id.home, new ButtonDispatcher(R.id.home));
}
    /* 根据id拿到准确目标 */
    public ButtonDispatcher getAllAppButton() {
        return mButtonDispatchers.get(R.id.all_app);
    }
 private void updateIcons(Configuration oldConfig) {
        mVolumeSubIcon = getDrawable(R.drawable.ic_sysbar_volume_sub_button);
        mAllAppIcon = getDrawable(R.drawable.ic_menu);  /*获取资源文件 */
        mScreenshotIcon = getDrawable(R.drawable.ic_sysbar_capture_button);
}
    public void updateNavButtonIcons() {
        getVolumeSubButton().setImageDrawable(mVolumeSubIcon);
        getAllAppButton().setImageDrawable(mAllAppIcon);    /* 设置图标 */
        getScreenshotButton().setImageDrawable(mScreenshotIcon);
}
  • 第五步:给allApp设置监听事件
    frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java
 private void prepareNavigationBarView() {
 	/* 王睿-设置监听 */
        ButtonDispatcher allAppButton = mNavigationBarView.getAllAppButton();
        allAppButton.setOnClickListener(this:: allAppClick);
}
   /* 王睿-点击事件 */
    private void allAppClick(View v) {
        Intent intent=new Intent("com.xxx.allApp");
        getContext().sendBroadcast(intent);
    }
  • 第六步:实现弹出全部应用
    packages / apps/Launcher3/src/com/android/launcher3/Launcher.java
@Override
    protected void onCreate(Bundle savedInstanceState) {
        registerReceiver(myReceiver, new IntentFilter("com.xxx.allApp"));	//动态注册广播
  }
 @Override
    public void onDestroy() {
  		unregisterReceiver(mScreenOffReceiver);
        unregisterReceiver(myReceiver);	//取消广播
        mWorkspace.removeFolderListeners();
  }
         /* 创建广播接收器 */
    private final BroadcastReceiver myReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            getStateManager().goToState(ALL_APPS);
        }
    };

Launcher 开发系列:
Launcher 在底部导航栏添加一个“☰”按钮,点击弹出全部应用
Launcher 修改底部导航虚拟按键的位置
Launcher 隐藏和开启底部虚拟按键(动态更改)
Launcher 去掉全部应用界面的搜索框
Launcher 点击鼠标右键时,显示菜单栏
Launcher 自定义一个虚拟按键实现返回主页和打开全部应用两个功能


点击全文阅读


本文链接:http://zhangshiyu.com/post/38464.html

设置  图标  弹出  
<< 上一篇 下一篇 >>

  • 评论(0)
  • 赞助本站

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

最新文章

  • (番外)+(全书)此去经年人未还全书+番外+后续免费下载_(沈青禾霍沉洲)此去经年人未还全书+番外+后续列表_笔趣阁(沈青禾霍沉洲)
  • 完结文毁容的姐姐和瞎眼的我离开后,姜家两兄弟悔哭了+后续列表_完结文毁容的姐姐和瞎眼的我离开后,姜家两兄弟悔哭了+后续(林梦婉)
  • 妻子辱我爸受贿自杀,我掏出一等军功章节选推荐_[陈素云辰朋友]小说精彩章节分享
  • 全书浏览苔藓爬满旧日诺言新上(顾砚廷慕晚夏)_苔藓爬满旧日诺言新上(顾砚廷慕晚夏)全书结局
  • 顾尘傅雅宁(神女老婆,却在背地承欢作乐+后续+结局)结局_(顾尘傅雅宁神女老婆,却在背地承欢作乐+后续+结局全书结局)结局列表_笔趣阁(顾尘傅雅宁)
  • 「老婆怀上助理的孩子后,助理要求我净身出户」章节限时抢先看‌_「黄秋雅秋雅姐刘嘉铭」后续完结版
  • 此去经年人未还,沈青禾霍沉洲_此去经年人未还,沈青禾霍沉洲
  • 我爸娶了九十九个媳妇都死了,这次准备娶我的女同学小说精彩章节免费试读_[小梅娶媳妇孤儿]全文免费在线阅读
  • 此去经年人未还结局+番外文章简述(沈青禾霍沉洲)列表_此去经年人未还结局+番外文章简述
  • 完结文寻你寻不到归期结局+完结列表_完结文寻你寻不到归期结局+完结(姜昭意盛西)
  • 江以蓁的潮起时问归期高分佳作江以蓁秦司礼全书在线
  • 「亲手逼死儿子后,男人悔不当初」后续全文免费阅读_[傅司衍轩轩佳佳]最新章节免费阅读

    关于我们 | 我要投稿 | 免责申明

    Copyright © 2020-2022 ZhangShiYu.com Rights Reserved.豫ICP备2022013469号-1