Determine whether there are virtual buttons (navigation bar)
Nowadays, a large number of mobile phones do not have virtual buttons, and some have one. We may use this knowledge when adapting.
For example: When the screen fills the entire screen, there is no way to fill the navigation bar together, but this is not what we want. We have to try paddingbottom for the layout. At this time, we have to judge whether there is a navigation bar and what the height of the navigation bar is.
/** * Get whether the NavigationBar exists * @param context * @return */ public boolean checkDeviceHasNavigationBar(Context context) { boolean hasNavigationBar = false; Resources rs = (); int id = ("config_showNavigationBar", "bool", "android"); if (id > 0) { hasNavigationBar = (id); } try { Class systemPropertiesClass = (""); Method m = ("get", ); String navBarOverride = (String) (systemPropertiesClass, ""); if ("1".equals(navBarOverride)) { hasNavigationBar = false; } else if ("0".equals(navBarOverride)) { hasNavigationBar = true; } } catch (Exception e) { } return hasNavigationBar; } /** * Get the virtual function key height * @param context * @return */ public int getVirtualBarHeigh(Context context) { int vh = 0; WindowManager windowManager = (WindowManager) (Context.WINDOW_SERVICE); Display display = (); DisplayMetrics dm = new DisplayMetrics(); try { @SuppressWarnings("rawtypes") Class c = (""); @SuppressWarnings("unchecked") Method method = ("getRealMetrics", ); (display, dm); vh = - ().getHeight(); } catch (Exception e) { (); } return vh; }
The above example of Android development in determining whether there are virtual buttons (navigation bars) is all the content I share with you. I hope you can give you a reference and I hope you can support me more.