Reputation: 19
I am trying to create an autocompletetextview at the bottom of a bottomsheet inside an activity.I want the dropdown to open above the autocompletetextview.
When keyboard is hidden it is displayed in the correct manner.-> Desired dropdown position
But when keyboard appears this dropdown appears over the keyboard. -> Problematic dropdown position
Here is my xml code.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="16dp"
android:theme="@style/Theme.MaterialComponents.Light.DarkActionBar.Bridge">
<TextView
android:id="@+id/txt_select_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:text="@string/select_date_range"
android:textSize="14sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/til_start_date"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:hint="@string/from_date"
app:endIconDrawable="@drawable/ic_calendar_24"
app:endIconMode="custom"
app:endIconTint="@color/colorPrimary"
app:layout_constraintEnd_toStartOf="@+id/til_end_date"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/txt_select_date"
app:layout_constraintWidth_percent="0.4">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/tiet_start_date"
android:layout_width="match_parent"
android:textSize="14sp"
android:focusableInTouchMode="false"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/til_end_date"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:hint="@string/end_date"
app:endIconDrawable="@drawable/ic_calendar_24"
app:endIconMode="custom"
app:endIconTint="@color/colorPrimary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/til_start_date"
app:layout_constraintTop_toBottomOf="@id/txt_select_date"
app:layout_constraintWidth_percent="0.4">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/tiet_end_date"
android:textSize="14sp"
android:focusableInTouchMode="false"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
<View
android:id="@+id/seperator1"
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:layout_marginTop="12dp"
android:background="@color/grey"
app:layout_constraintTop_toBottomOf="@id/til_end_date" />
<TextView
android:id="@+id/txt_show_archived"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="@string/show_archived_calls"
android:textSize="14sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/seperator1" />
<CheckBox
android:id="@+id/checkbox_show_archived"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:buttonTint="@color/colorPrimary"
app:layout_constraintBottom_toBottomOf="@id/txt_show_archived"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/txt_show_archived" />
<View
android:id="@+id/seperator2"
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:layout_marginTop="16dp"
android:background="@color/grey"
app:layout_constraintTop_toBottomOf="@id/txt_show_archived" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/til_select_members"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:hint="@string/select_team_members"
app:layout_constraintTop_toBottomOf="@id/seperator2">
<com.google.android.material.textfield.MaterialAutoCompleteTextView
android:id="@+id/actv_members"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingVertical="16dp"
android:paddingStart="12dp"
android:text="@string/all_team_members"
android:textColor="@color/grey"
android:textSize="14sp" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.button.MaterialButton
android:id="@+id/btn_filter_apply"
style="@style/Widget.MaterialComponents.Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:backgroundTint="@color/colorPrimary"
android:text="@string/apply"
android:textAllCaps="false"
android:textAppearance="@style/TextAppearance.MaterialComponents.Body2"
android:textColor="@color/white"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/til_select_members" />
<com.google.android.material.button.MaterialButton
android:id="@+id/btn_filter_clear"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="@string/clear_filters"
android:textAllCaps="false"
android:textAppearance="@style/TextAppearance.MaterialComponents.Body2"
app:layout_constraintEnd_toStartOf="@id/btn_filter_apply"
app:layout_constraintTop_toBottomOf="@id/til_select_members" />
<com.google.android.material.button.MaterialButton
android:id="@+id/btn_cancel_filter"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="@string/cancel"
android:textAllCaps="false"
android:textAppearance="@style/TextAppearance.MaterialComponents.Body2"
app:layout_constraintEnd_toStartOf="@id/btn_filter_clear"
app:layout_constraintTop_toBottomOf="@id/til_select_members" />
</androidx.constraintlayout.widget.ConstraintLayout>
What I have already tried:
Upvotes: 1
Views: 733
Reputation: 19
The problem is that the bottom sheet must be fully expanded in order to prevent hiding behind the keyboard for small screens.You need to explicity set the state to expanded. One can solve this problem by adding the following code :
// open bottom sheet as fully expanded to prevent hiding behind keyboard in small screens
Objects.requireNonNull(getDialog()).setOnShowListener(dialog -> {
BottomSheetDialog btmShtDialog = (BottomSheetDialog) dialog;
FrameLayout bottomSheet = btmShtDialog.findViewById(com.google.android.material.R.id.design_bottom_sheet);
if (bottomSheet != null) {
BottomSheetBehavior.from(bottomSheet).setState(BottomSheetBehavior.STATE_EXPANDED);
}
});
Upvotes: 0