相关文件
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
- 第二步:控制导航键显示位置
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
all_app;back,home,recent;right
- 第三步:在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) {
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));
}
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 自定义一个虚拟按键实现返回主页和打开全部应用两个功能



