4

I have a BottomSheetwith a EditText, when the keyboard appears the BottomSheet should go over the keyboard.

enter image description here

So I added to the Manifest.xml: android:windowSoftInputMode="stateVisible|adjustResize" oradjustPan But as you can see in the picture the keyboard goes over the BottomSheet.

The code for the BottomSheet:

bottomSheetViewNewPocketItem = findViewById(R.id.bottomSheetNewPocketItem);
// BottomSheet new pocket item
bottomSheetBehaviorNewPocketItem = BottomSheetBehavior.from(bottomSheetViewNewPocketItem);
bottomSheetBehaviorNewPocketItem.setPeekHeight(200);
bottomSheetBehaviorNewPocketItem.setHideable(true);

My manifest looks like this:

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

And the 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>
Dr Mido
  • 2,414
  • 4
  • 32
  • 72
J.Doe
  • 177
  • 1
  • 2
  • 13
  • this link can solve your issue: https://stackoverflow.com/questions/39288879/bottom-sheet-fragment-comes-up-with-keyboard – android Apr 20 '19 at 17:43
  • Hey @android, bevor I ask a question I try different solutions from other questions. So I tried this too, but it's different then my code, I dont useBottomSheetDialog so can't use getDialog(). So no, it's not solving my issue. – J.Doe Apr 20 '19 at 17:47
  • Did you find the solution for this issue? @J.Doe – jpvillegas Jun 02 '23 at 20:08

1 Answers1

0

I place my EditText (or all hideable bottomsheet content) in Scrollview and it works in my code. Maybe it can help you.

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