【问题标题】:Android BottomSheetDialogFragment hides behind keyboardAndroid BottomSheetDialogFragment 隐藏在键盘后面
【发布时间】:2020-07-18 08:45:21
【问题描述】:

我想在键盘打开时在屏幕顶部显示我的 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 方法中。但是我的问题没有解决。我该怎么办?

【问题讨论】:

    标签: android android-studio android-layout android-bottomsheetdialog


    【解决方案1】:

    我把我的风格改成了这个,我的问题解决了:

    <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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-22
      • 2022-01-23
      • 2014-11-06
      • 1970-01-01
      • 1970-01-01
      • 2021-07-23
      • 2020-10-15
      • 2016-10-22
      相关资源
      最近更新 更多