Vla*_*lad 26 controls android navigationbar
我正在用一个AppCompatDialogFragment来展示一个BottomSheetDialog.单击Navigation Bar关闭后面的后退按钮BottomSheetDialog.
我想Navigation Bar将后退按钮上的图标更改为"向下箭头"图标.默认情况下,这是在显示键盘时完成的,我想为底部工作表复制它.
要清楚,这里有我所拥有的:
这就是我需要的:
请注意,后退按钮是"向下箭头".
导航栏是一个系统ui组件,我没有看到改变它的外观的方式,看起来像键盘可见时显示的导航栏.
在Android O中,引入了更改图标的概念,但它仍然通过第三方应用程序.自定义导航栏使用WRITE_SECURE_SETTINGS更改的图标.在Android O中,您可以更改栏的显示,即浅色或深色主题.
解决方案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);
Run Code Online (Sandbox Code Playgroud)
对于最近的应用.
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);
Run Code Online (Sandbox Code Playgroud)
对于Back Button //使用您的图标和关闭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;
}
Run Code Online (Sandbox Code Playgroud)
你也可以通过adb命令来做到这一点,但要确保它可以弄乱你的navigationBar,你无法取回你的原件navigationBar.
我希望它有所帮助.