功能:Android 系统底部导航栏(HOME\BACK)位置添加截图按钮,系统设置界面添加截图开关
主要修改工程有SystemUI 和 Settings
注意:不同的ANDROID SDK源码存在部分差异,流程是相同的,仅供参考!
效果图如下:

本章节分3部分:导航栏修改>完善截图功能>系统设置添加选项
阅读SystemUI源码,了解如何加载导航栏布局,确定对应的布局xml文件以及相关java类
该soc厂商加载导航栏布局
在:SystemUI\app\src\main\res\layout\navigation_bar.xml
通过调整xml布局,添加截图按钮和对应的icon资源!
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:visibility="invisible"
android:background="@drawable/cp_screen_icon"
android:id="@+id/cp_screen"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
/>
找到加载底部导航栏xml的类,一般是StatusBar.java
方法1:
导航栏是在createNavigationBar函数中进行解析加载到页面的
在这里可以通过mNavigationBarView.findViewById(R.id.cp_screen);获取截图按钮对象.
拿到对象后设置其点击事件即可.
方法2:
NavigationBarView也可在该类findViewById获取截图按钮做相关逻辑.
SystemUI google本身为我们集成的截图功能,我们只需引用即可.
在此之前