android - 带有 softInputMode 的全屏 DialogFragment 调整调整大小
问题描述
所以我有一个 DialogFragment,我使用以下代码在 onResume 中扩展到整个屏幕:
val params = dialog?.window?.attributes
params?.width = ViewGroup.LayoutParams.MATCH_PARENT
params?.height = ViewGroup.LayoutParams.MATCH_PARENT
dialog?.window?.attributes = params as WindowManager.LayoutParams
我也使用以下样式:
<style name="AppTheme.FullscreenDialogFragment" parent="Theme.MaterialComponents.Light.Dialog">
<item name="android:windowIsFloating">false</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:windowBackground">@color/background1</item>
</style>
现在我还希望它在状态栏下扩展,我通过以下方式执行此操作(我还将状态栏颜色设置为透明):
dialog?.window?.decorView?.systemUiVisibility =
View.SYSTEM_UI_FLAG_LAYOUT_STABLE.addFlag(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)
这一切都很好,但现在我想将 softInputMode 调整为 adjustResize。我就是无法让它工作。只有当我删除上面的布局标志时它才有效。它在正常片段中工作正常。有没有人知道我在这里缺少什么,或者 DialogFragment 是不可能的?
解决方案
所以我的问题不是DialogFragment,而是当你在系统栏下绘制布局时Android不尊重adjustResize的事实。为防止这种情况发生,您需要收听 Window insets 并将它们作为填充应用到您的布局中,以便当键盘打开时,底部 inset 会使您的整个内容变小,并且 ScrollView 可以滚动到底部。我将以下库用于插图:
推荐阅读
- elasticsearch - 在 Kubernetes 中使用 helm 的 Logstash:grok 过滤器不起作用
- sql - 午夜事务的 SQL 查询
- javascript - 当模式关闭vue时如何运行语句?
- android - 删除以编程方式添加的RelativeLayout.END_OF,android 5.0我不能,但android 8我可以
- python - 读取 URL 不显示其内容
- mysql - 如何使用 MySQL 过程在同一服务器的另一个数据库中动态创建表?
- php - 按字母顺序对集合进行排序
- node.js - logstash vs nodejs应用程序的任务队列
- python - Python目录爬虫扫描各类文件并搜索关键字
- reactjs - 使用 react-router v4 更改 url 中的参数之一