android - Android BottomSheetDialogFragment 隐藏在键盘后面
问题描述
我想在键盘打开时在屏幕顶部显示我的BottomSheetDIalogFragment 。我在网上搜索并找到了一些解决方案,但没有人能解决我的问题。我加
android:windowSoftInputMode="adjustResize"
到我的AndroidMnifest.xml。我的对话风格是:
<style name="CustomBottomSheetDialogTheme" parent="Theme.Design.Light.BottomSheetDialog">
<item name="bottomSheetStyle">@style/CustomBottomSheetStyle</item>
</style>
<style name="CustomBottomSheetStyle" parent="Widget.Design.BottomSheet.Modal">
<item name="android:background">@android:color/transparent</item>
<item name="android:windowIsFloating">false</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:windowSoftInputMode">adjustResize</item>
<item name="android:windowTranslucentStatus">false</item>
</style>
在java中:
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(BottomSheetDialogFragment.STYLE_NORMAL, R.style.CustomBottomSheetDialogTheme);
}
和
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
BottomSheetDialog dialog = (BottomSheetDialog) super.onCreateDialog(savedInstanceState);
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
BottomSheetDialog d = (BottomSheetDialog) dialog;
FrameLayout bottomSheet = (FrameLayout) d.findViewById(com.google.android.material.R.id.design_bottom_sheet);
BottomSheetBehavior.from(bottomSheet).setState(BottomSheetBehavior.STATE_EXPANDED);
}
});
return dialog;
}
和
if (getDialog() != null && getDialog().getWindow() != null) {
getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
}
在onCreateView方法中。但是我的问题没有解决。我应该怎么办?
解决方案
我改变了我的风格,我的问题解决了:
<style name="CustomBottomSheetDialogTheme" parent="Theme.Design.Light.BottomSheetDialog">
<item name="bottomSheetStyle">@style/CustomBottomSheetStyle</item>
<item name="android:background">@android:color/transparent</item>
<item name="android:windowIsFloating">false</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:windowSoftInputMode">adjustResize</item>
<item name="android:windowTranslucentStatus">false</item>
</style>
<style name="CustomBottomSheetStyle" parent="Widget.Design.BottomSheet.Modal">
<item name="android:background">@android:color/transparent</item>
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
推荐阅读
- docusignapi - DocuSign 电子签名:在签名窗口出现错误“不支持此身份验证模式:无”
- javascript - 寻找一种简单的方法来从一个 HTML 页面中获取一个值并让它出现在另一个页面中。下面的例子:
- c# - 用 ObservableCollection 替换 ICollection 是否明智
wpf ef - html - 无法将文本和复选框放在同一行
- cakephp - 如何为插件禁用 CSRF?
- f# - 为什么 F# 有这么复杂的比较运算符?
- elasticsearch - flink-kafka-elasticsearch 部署在纱线上
- django - Spring/SpringBoot 管理面板,如 Django Admin
- javascript - 验证后失败:标题:路径`title`是必需的。在mongodb中
- python - 将字典值转换为列表内