WRITE_SECURE_SETTINGS
更改图标。
在Android O中,您可以更改导航栏的显示,即浅色或深色主题。
Solution 2可能对您更有帮助。
您可以在导航栏上创建一个带有所需布局(即3个按钮“返回”、“最近使用的应用”和“主页”)的popup window
。这样,您就可以相应地更改“返回”按钮图标。确保弹出窗口与导航栏具有相同的高度,然后可以为主页和最近使用的应用程序编写自己的功能,在“返回”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的功能。
用于计算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
,否则你将无法恢复原始状态。
希望这能帮到你。
弹出窗口
放置在导航栏
之上?我需要将我的应用程序设置为沉浸模式吗? - Vlad正如已经回答的那样,它将在Android O中引入。
对于之前的版本,只有在Android 3.x或使用标志时才可能实现4.4+,例如SYSTEM_UI_FLAG_IMMERSIVE
,SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
,SYSTEM_UI_FLAG_HIDE_NAVIGATION
等。但仍然非常有限,即使付出很多努力,你得到的结果也不是非常友好甚至会有问题。
无法实现的原因是安全问题。应用程序可能会阻止用户退出应用程序。
请查看以下链接:
BottomDialog
时,我希望显示一个向下的箭头。当点击返回按钮时,BottomDialog
会通过向下滑动消失,因此显示一个向下的箭头而不是传统的返回按钮是有意义的。 - Vlad