在 android O 中引入了更改图标的概念,但仍然是通过 3rd 方应用程序。 Custom Navigation Bar 使用 WRITE_SECURE_SETTINGS 更改图标。
在 Android O 中,您可以更改栏的显示,即 Light 或 Dark 主题。
解决方案 2 可以为您提供更多帮助。
您可以使用所需的布局在导航栏上创建popup window,即 3 个返回按钮、最近的应用程序和主页按钮。通过这种方式,您可以相应地更改后退按钮图标。确保弹出窗口与导航栏高度相同,然后您可以为家庭和最近的应用程序创建自己的功能,在function 后面,您可以关闭您的BottomSheetDialog 并删除该弹出窗口。
以下是 Home 键以及最近的应用程序的代码。对于后退按钮,请使用您自己的图标相应地执行您想要实现的操作。
对于主页按钮。
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
对于最近的应用程序。
Class serviceManagerClass = Class.forName("android.os.ServiceManager");
Method getService = serviceManagerClass.getMethod("getService", String.class);
IBinder retbinder = (IBinder) getService.invoke(serviceManagerClass, "statusbar");
Class statusBarClass = Class.forName(retbinder.getInterfaceDescriptor());
Object statusBarObject = statusBarClass.getClasses()[0].getMethod("asInterface", IBinder.class).invoke(null, new Object[] { retbinder });
Method clearAll = statusBarClass.getMethod("toggleRecentApps");
clearAll.setAccessible(true);
clearAll.invoke(statusBarObject);
返回按钮
// 使用你的图标和关闭BottomSheetDialog的功能。
用于计算navigationBar的高度
public static int getSoftButtonsBarSizePort(Activity activity) {
// getRealMetrics is only available with API 17 and +
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
DisplayMetrics metrics = new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
int usableHeight = metrics.heightPixels;
activity.getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
int realHeight = metrics.heightPixels;
if (realHeight > usableHeight)
return realHeight - usableHeight;
else
return 0;
}
return 0;
}
您也可以通过adb 命令执行此操作,但请确保它会弄乱您的navigationBar,并且您无法取回原来的navigationBar。
希望对你有帮助。