我正在使用AppCompatDialogFragment
来显示一个BottomSheetDialog
。 单击Navigation Bar
上的后退button将closuresBottomSheetDialog
。
我想将Navigation Bar
上的图标从后退button更改为“向下箭头”图标。 这是默认情况下完成键盘显示,我想复制它的底部工作表。
要清楚,在这里我有:
这就是我所需要的:
请注意,后退button是“向下箭头”。
导航栏是一个system-ui组件,我没有看到改变它的外观的方式,看起来像键盘可见时显示的导航栏。
在android中,引入了更改图标的概念,但它仍然通过第三方应用程序。 使用WRITE_SECURE_SETTINGS
更改图标的自定义导航栏 。 在Android O中,您可以更改条形图的显示,即Light或Dark主题。
解决scheme2可以更多的帮助你。 您可以在导航栏上创build一个带有所需布局的popup window
,例如3个button,最近应用和主页button。 通过这种方式,您可以相应地更改后退button图标。 确保popup窗口的高度与导航栏的高度相同,然后您可以为家庭和最近的应用程序创build自己的function,并在后退function
中closuresBottomSheetDialog
并删除该popup窗口。
下面是家庭密钥以及最近的应用程序的代码。 对于后退button,请根据自己的图标做相应的操作。
为主页button。
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);
对于后退button//使用您的图标和closuresBottomSheetDialog的function。
用于计算导航条的高度
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
。
我希望它有帮助。
正如已经回答的那样,它将在Android O中引入。
对于以前的版本,只能使用Android 3.x或4.4+使用标志,如SYSTEM_UI_FLAG_IMMERSIVE
, SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
, SYSTEM_UI_FLAG_HIDE_NAVIGATION
等。但仍然非常有限,付出很大的努力,你会得到一个结果不是很友善,甚至是不好的。
原因是因为这是不可能的,因为这是一个安全问题。 应用程序可以阻止用户退出应用程序。
看看这些链接:
这篇文章描述了可以在Android Oreo中完成的锄头。