Android虚拟键(NavigationBar)适配

Android虚拟键适配,之前我一直没有在乎过,因为一般我都是自动适应布局,但是最近用到一个界面效果,自己写了一个PopupWindow,造成了类似的效果

《Android虚拟键(NavigationBar)适配》 未适配图

  • 可以发现,虚拟键位,挡住了取消按钮的触控区域,网上百度一下,大多是在布局内家加上(android:fitsSystemWindows=”true”) ,BUT我的控件不是布局,里面写好的啊!我采用的自定义布局,SO 问题就是如何让取消按钮的触控区域显示出来。

采用隐藏虚拟键位的方法。
百度一下(原谅我红杏被封了,我就沦落到百度了,鄙视我吧),以下是结果:

``` 

getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
getWindow().getDecorView().setSystemUiVisibility(View.STATUS_BAR_HIDDEN);
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_SHOW_FULLSCREEN);
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);

what the fuck   ,上面是什么鬼,试了一下,开始是隐藏的,但是点击布局,又显示出来了,还有建议屏蔽View点击事件,抛弃


+  获取虚拟键高度,然后定位显示布局的位置

      ``` 
public staticPointgetNavigationBarSize(Context context) {
Point appUsableSize =getAppUsableScreenSize(context);
Point realScreenSize =getRealScreenSize(context);
// navigation bar on the right
if(appUsableSize.x< realScreenSize.x) {
return newPoint(realScreenSize.x- appUsableSize.x,appUsableSize.y);
}
// navigation bar at the bottom
if(appUsableSize.y< realScreenSize.y) {
return newPoint(appUsableSize.x,realScreenSize.y- appUsableSize.y);
}
// navigation bar is not present
return newPoint();
}
public staticPointgetAppUsableScreenSize(Context context) {
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = windowManager.getDefaultDisplay();
Point size =newPoint();
display.getSize(size);
returnsize;
}
public staticPointgetRealScreenSize(Context context) {
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = windowManager.getDefaultDisplay();
Point size =newPoint();
if(Build.VERSION.SDK_INT>=17) {
display.getRealSize(size);
}else if(Build.VERSION.SDK_INT>=14) {
try{
size.x= (Integer) Display.class.getMethod("getRawWidth").invoke(display);
size.y= (Integer) Display.class.getMethod("getRawHeight").invoke(display);
}catch(IllegalAccessException e) {}catch(InvocationTargetException e) {}catch(NoSuchMethodException e) {}
}
returnsize;
}
  ``` 



* 测试:虚拟键位正常显示在布局下面,还有LG的手机真的很丑。。。(当然,APP丑这是肯定的)

![适配后图](http://upload-images.jianshu.io/upload_images/555358-ecb28a26256bee7e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

链接地址:[stackOverFlow](http://stackoverflow.com/questions/20264268/how-to-get-height-and-width-of-navigation-bar-programmatically/29609679#29609679)
顺便说一下:国内技术都是一篇文章处处转,标个原地址能死啊!(鄙视。。。。。)
    原文作者:Keike
    原文地址: https://www.jianshu.com/p/101fdd3ba6a9
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞