我正在使用 AndroidResideMenu ( https://github.com/SpecialCyCi/AndroidResideMenu ),并且发现了与 View 大小相关的问题。
该库的工作原理是膨胀 FrameLayout,从 DecorView 中删除当前 View 并将其添加到新的 FrameLayout(其中还包含用于添加菜单项的 ScrollView 和阴影 View )。
旧 View 保持其大小和位置,但新的 FrameLayout 似乎处于全屏模式,并且当菜单打开时隐藏在状态栏下方,正如我在此处所述 ( https://github.com/SpecialCyCi/AndroidResideMenu/issues/33 )。
在 api14+ 设备中,可以通过在 ResideMenu 中添加对 setFitsSystemWindow(true) 的调用来解决问题,但我不知道在旧设备中该怎么做。
有想法吗?
谢谢!
最佳答案
嗯,我已经找到解决办法了。
只需实现方法 fitSystemWindows(Rect insets)
,按照该方法的文档中所述进行操作(直到现在我还误解了):
The default implementation of this method simply applies the content insets to the view's padding, consuming that content (modifying the insets to be 0), and returning true. This behavior is off by default, but can be enabled through setFitsSystemWindows(boolean).
因此,在 ResideMenu
类中:
@Override
protected boolean fitSystemWindows(Rect insets) {
setPadding(paddingLeft + insets.left, paddingTop + insets.top, ...);
insets.left = insets.top = insets.right = insets.bottom = 0;
return true;
}
希望这有帮助!
关于Android DecorView setFitsSystemWindows,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27060511/