在安卓Ø改变图标的概念引入,但它仍然是通过第三方应用程序。 Custom Navigation Bar使用WRITE_SECURE_SETTINGS
更改图标。 在Android O中,您可以更改酒吧的显示,即Light或Dark主题。
解决方案2可能更多的是对您有所帮助。 您可以在导航栏上创建一个popup window
,具有所需的布局,例如3个按钮,最近的应用和主页按钮。通过这种方式,您可以相应地更改后退按钮图标。确保弹出窗口是相同的高度导航栏,然后你可以使自己的功能产品和最新的应用程序,并在后面function
您可以关闭BottomSheetDialog
并删除弹出式窗口。
下面是主页键以及最近应用程序的代码。对于后退按钮,请根据自己的图标做相应的操作。
对于主页按钮。
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的功能。
对于由adb
命令计算的的导航栏
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;
}
你也可以做到这一点的高度,但要确保它可以搞砸你的navigationBar
,你不能回到原来的navigationBar
。
我希望它有帮助。
只有打开键盘时才会显示向下箭头。我很好奇你有什么用例?因为如果它只是一个愿望,比你还可以说*“我想要一个八角形而不是主页按钮”*。你想成为一个坏男孩并且违反规则,这意味着用户肯定知道在什么情况下箭头变成了箭头向下,并且你想在那里引入根本性的改变,显然谷歌不允许这样做,因为用户体验应该是贯穿整个平台。 – azizbekian
@azizbekian我想在显示'BottomDialog'时显示向下箭头。当点击后退按钮时,'BottomDialog'被滑下来消除,显示向下箭头而不是传统的后退按钮是有意义的。 – Vlad
@azizbekian API允许您更改后退按钮的行为,因此允许您更改关联的图标是有意义的。 – ben75