1. Are you ready for the Galaxy S20? Here is everything we know so far!

Keyboard over BottomSheet(Dialog) problem

Discussion in 'Android Development' started by Lalox3, Apr 20, 2019.

  1. Lalox3

    Lalox3 Lurker
    Thread Starter

    Hello people.

    I do use BottomSheetDialog and there are some Edittext etc...
    But the problem is that when the keyboard pops up, not the whole
    BottomSheet is over the Keyboard.

    I've tried:
    d.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    and any SOFT_INPUT parameter. Nothing is changing ._.

    [​IMG]

    MainActivity
    Code (Java):
    1.         final BottomSheetDialog d  = new BottomSheetDialog(this);
    2.         Objects.requireNonNull(d.getWindow()).setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    3.         d.setContentView(R.layout.content_bottomsheet_new_pocket_item);
    4.         d.getBehavior().setHideable(true);
    5.         d.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
    6.  
    7.         button2.setOnClickListener(new View.OnClickListener() {
    8.            @Override
    9.            public void onClick(View view) {
    10.                d.show();
    11.            }
    12.         });

    Main Activity.xml
    Code (Text):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    3.     xmlns:app="http://schemas.android.com/apk/res-auto"
    4.     xmlns:tools="http://schemas.android.com/tools"
    5.     android:id="@+id/coordinatorLayoutPocketMain"
    6.     android:layout_width="match_parent"
    7.     android:layout_height="match_parent"
    8.     android:fitsSystemWindows="false"
    9.     tools:context=".PocketMain">
    10.  
    11.     <com.google.android.material.appbar.AppBarLayout
    12.         android:id="@+id/app_bar"
    13.         android:layout_width="match_parent"
    14.         android:layout_height="@dimen/app_bar_height"
    15.         android:fitsSystemWindows="true"
    16.         android:theme="@style/AppTheme.AppBarOverlay">
    17.  
    18.         <com.google.android.material.appbar.CollapsingToolbarLayout
    19.             android:id="@+id/toolbar_layout"
    20.             android:layout_width="match_parent"
    21.             android:layout_height="match_parent"
    22.             android:fitsSystemWindows="true"
    23.             app:contentScrim="?attr/colorPrimary"
    24.             app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
    25.             app:toolbarId="@+id/toolbar">
    26.  
    27.             <androidx.appcompat.widget.Toolbar
    28.                 android:id="@+id/toolbar"
    29.                 android:layout_width="match_parent"
    30.                 android:layout_height="?attr/actionBarSize"
    31.                 android:layout_marginTop="22dp"
    32.                 app:layout_collapseMode="pin"
    33.                 app:popupTheme="@style/AppTheme.PopupOverlay" />
    34.  
    35.             <androidx.constraintlayout.widget.ConstraintLayout
    36.                 android:layout_width="match_parent"
    37.                 android:layout_height="75dp"
    38.                 android:layout_gravity="bottom">
    39.  
    40.                 <Button
    41.                     android:id="@+id/button2"
    42.                     android:layout_width="wrap_content"
    43.                     android:layout_height="wrap_content"
    44.                     android:layout_marginStart="8dp"
    45.                     android:layout_marginTop="8dp"
    46.                     android:layout_marginEnd="8dp"
    47.                     android:layout_marginBottom="8dp"
    48.                     android:text="Button"
    49.                     app:layout_constraintBottom_toBottomOf="parent"
    50.                     app:layout_constraintEnd_toEndOf="parent"
    51.                     app:layout_constraintStart_toStartOf="parent"
    52.                     app:layout_constraintTop_toTopOf="parent" />
    53.  
    54.             </androidx.constraintlayout.widget.ConstraintLayout>
    55.  
    56.         </com.google.android.material.appbar.CollapsingToolbarLayout>
    57.     </com.google.android.material.appbar.AppBarLayout>
    58.  
    59.     <include layout="@layout/content_pocket_main" />
    60.  
    61. </androidx.coordinatorlayout.widget.CoordinatorLayout>
    content_bottomsheet_new_pocket_item.xml
    Code (Text):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    3.     xmlns:app="http://schemas.android.com/apk/res-auto"
    4.     xmlns:tools="http://schemas.android.com/tools"
    5.     android:layout_width="match_parent"
    6.     android:layout_height="wrap_content"
    7.     android:background="@color/colorPrimary">
    8.  
    9.     <Button
    10.         android:id="@+id/button"
    11.         android:layout_width="wrap_content"
    12.         android:layout_height="wrap_content"
    13.         android:layout_marginStart="8dp"
    14.         android:layout_marginTop="32dp"
    15.         android:layout_marginEnd="8dp"
    16.         android:text="Button"
    17.         app:layout_constraintEnd_toEndOf="parent"
    18.         app:layout_constraintStart_toStartOf="parent"
    19.         app:layout_constraintTop_toTopOf="parent" />
    20.  
    21.     <EditText
    22.         android:id="@+id/editText"
    23.         android:layout_width="wrap_content"
    24.         android:layout_height="wrap_content"
    25.         android:layout_marginStart="8dp"
    26.         android:layout_marginTop="8dp"
    27.         android:layout_marginEnd="8dp"
    28.         android:layout_marginBottom="60dp"
    29.         android:ems="10"
    30.         android:inputType="textPersonName"
    31.         android:text="Name"
    32.         app:layout_constraintBottom_toBottomOf="parent"
    33.         app:layout_constraintEnd_toEndOf="parent"
    34.         app:layout_constraintStart_toStartOf="parent"
    35.         app:layout_constraintTop_toBottomOf="@+id/button" />
    36.  
    37.     <EditText
    38.         android:id="@+id/editText2"
    39.         android:layout_width="wrap_content"
    40.         android:layout_height="wrap_content"
    41.         android:layout_marginBottom="8dp"
    42.         android:ems="10"
    43.         android:inputType="textPersonName"
    44.         android:text="Name"
    45.         app:layout_constraintBottom_toBottomOf="parent"
    46.         app:layout_constraintEnd_toEndOf="parent"
    47.         app:layout_constraintStart_toStartOf="parent" />
    48.  
    49. </androidx.constraintlayout.widget.ConstraintLayout>
     


  2. Deleted User

    Deleted User Guest

    I really don't know why Android Studio makes ConstraintLayout the default for new projects. ConstraintLayout is NOT the best choice for simple layouts, especially for beginners. You would be better off using simple LinearLayouts.
     
  3. Lalox3

    Lalox3 Lurker
    Thread Starter

    Um, your answer is not related to my question. So has it something to do with the ConstraintLayout?
     
  4. Deleted User

    Deleted User Guest

    Yes. My point was, not to use ConstraintLayout for such a simple UI.
     
  5. Lalox3

    Lalox3 Lurker
    Thread Starter

    I like the ConstraintLayout and the LinearLayout didn't fixed my problem. So I don't get your point.
     
  6. Deleted User

    Deleted User Guest

    Ok well it was something to try. Good luck with figuring it out.
     
  7. Lalox3

    Lalox3 Lurker
    Thread Starter

    Well after searching for the whole night for a solution I'm using a custom dialog now ...
     
  8. Deleted User

    Deleted User Guest

    Good stuff. Well done getting it sorted.
     
Loading...
Similar Threads - Keyboard BottomSheet Dialog
  1. Elgaban
    Replies:
    1
    Views:
    120
  2. cwr64
    Replies:
    2
    Views:
    282
  3. tr00don
    Replies:
    0
    Views:
    596
  4. Omega01
    Replies:
    1
    Views:
    357
  5. Ravindra Pal Singh
    Replies:
    0
    Views:
    622
  6. Mahmudul001
    Replies:
    0
    Views:
    571
  7. ccoffey3131
    Replies:
    0
    Views:
    350
  8. GamerROMInc
    Replies:
    0
    Views:
    430
  9. Abdul Malik Khattak
    Replies:
    14
    Views:
    1,073
  10. MattC123
    Replies:
    0
    Views:
    404

Share This Page

Loading...