windowSoftInputMode与BottomSheet不起作用

4

我有一个带有EditTextBottomSheet,当键盘出现时,BottomSheet应该覆盖在键盘上方。

enter image description here

所以我在Manifest.xml中添加了:android:windowSoftInputMode="stateVisible|adjustResize"adjustPan,但是从图片中可以看到键盘覆盖了BottomSheetBottomSheet的代码:
bottomSheetViewNewPocketItem = findViewById(R.id.bottomSheetNewPocketItem);
// BottomSheet new pocket item
bottomSheetBehaviorNewPocketItem = BottomSheetBehavior.from(bottomSheetViewNewPocketItem);
bottomSheetBehaviorNewPocketItem.setPeekHeight(200);
bottomSheetBehaviorNewPocketItem.setHideable(true);

我的清单看起来像这样:

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/CoinMasterTheme">
    <activity
        android:name=".PocketMain"
        android:label="@string/app_name"
        android:windowSoftInputMode="stateVisible|adjustResize"
        android:theme="@style/CoinMasterTheme">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

还有 activity_pocket_main.xml 文件:

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/coordinatorLayoutPocketMain"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="false"
    tools:context=".PocketMain">

<com.google.android.material.appbar.AppBarLayout
    android:id="@+id/app_bar"
    android:layout_width="match_parent"
    android:layout_height="@dimen/app_bar_height"
    android:fitsSystemWindows="true"
    android:theme="@style/AppTheme.AppBarOverlay">

    <com.google.android.material.appbar.CollapsingToolbarLayout
        android:id="@+id/toolbar_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
        app:toolbarId="@+id/toolbar">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:layout_marginTop="22dp"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>

<include layout="@layout/content_pocket_main" />

<androidx.core.widget.NestedScrollView
    android:id="@+id/bottomSheetNewPocketItem"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:elevation="5dp"
    android:fillViewport="true"
    app:layout_behavior="@string/bottom_sheet_behavior">

    <include layout="@layout/content_bottomsheet_new_pocket_item" />
</androidx.core.widget.NestedScrollView>

 </androidx.coordinatorlayout.widget.CoordinatorLayout>

这个链接可以解决你的问题:https://dev59.com/IVkS5IYBdhLWcg3w6qXU - android
嘿@android,在我提问之前,我会尝试其他问题的不同解决方案。所以我也尝试了这个,但它与我的代码不同,我没有使用BottomSheetDialog,因此无法使用getDialog()。所以,不,它不能解决我的问题。 - J.Doe
你找到这个问题的解决方案了吗?@J.Doe - jpvillegas
1个回答

0

我将我的EditText(或所有可隐藏的底部表单内容)放在ScrollView中,它在我的代码中运行良好。也许这可以帮助你。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/activity_lesson_bottom_sheet"
    android:layout_width="match_parent"
    android:layout_height="340dp"
    android:orientation="vertical"
    app:behavior_hideable="false"
    app:behavior_peekHeight="60dp"
    app:behavior_saveFlags="all"
    app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">

    <FrameLayout
        android:id="@+id/activity_lesson_bottom_sheet_title"
        android:layout_width="match_parent"
        android:layout_height="60dp">

        <FrameLayout
            android:id="@+id/activity_lesson_bottom_sheet_title_background"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:alpha="00"
            android:background="#22FF0000" />

        <TextView
            style="@style/ButtonSimpleStyle"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="Привет, я текст" />
    </FrameLayout>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true">

        <EditText
            style="@style/ButtonSimpleStyle"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#22FF00FF"
            android:gravity="center"
            android:text="Привет, я скрытый текст" />
    </ScrollView>
</LinearLayout>

无法使其工作。您是否应用了其他设置?也许在清单文件中? - jpvillegas

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接