具体原因以及参考的文章,暂时无法找到。以下是在下项目中的使用,请各位客官见谅。
小编在activity基类的setContentView(R.layout......)后,添加
//这个是沉浸式状态栏AndroidBug54971Workaround.assistActivity(viewById);//这应该是设置虚拟键盘背景色if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {getWindow().setNavigationBarColor(Color.WHITE);}
AndroidBug54971Workaround类如下,没有包信息和倒类信息,studio可自动导入:
public class AndroidBug54971Workaround {// For more information, see /p/android/issues/detail?id=5497// To use this class, simply invoke assistActivity() on an Activity that already has its content view set./*** 关联要监听的视图** @param viewObserving*/public static void assistActivity(View viewObserving) {new AndroidBug54971Workaround(viewObserving);}private View mViewObserved;//被监听的视图private int usableHeightPrevious;//视图变化前的可用高度private ViewGroup.LayoutParams frameLayoutParams;private AndroidBug54971Workaround(View viewObserving) {mViewObserved = viewObserving;//给View添加全局的布局监听器mViewObserved.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {@Overridepublic void onGlobalLayout() {resetLayoutByUsableHeight(computeUsableHeight());}});frameLayoutParams = mViewObserved.getLayoutParams();}private void resetLayoutByUsableHeight(int usableHeightNow) {//比较布局变化前后的View的可用高度if (usableHeightNow != usableHeightPrevious) {//如果两次高度不一致//将当前的View的可用高度设置成View的实际高度frameLayoutParams.height = usableHeightNow;mViewObserved.requestLayout();//请求重新布局usableHeightPrevious = usableHeightNow;}}/*** 计算视图可视高度** @return*/private int computeUsableHeight() {Rect r = new Rect();mViewObserved.getWindowVisibleDisplayFrame(r);//r.top这个会减去状态栏的高度return r.bottom;// return (r.bottom - r.top);}}
通过这样的设置,可是的全面屏下方显示安卓的返回、home、菜单三个选项键。
但是具体的背景颜色,用户可自动设置。具体设置方法、注释可在上方找到。
鸡汤一份:
你不擅长的地方,恰恰说明有很大的提升空间,加油!