对话框片段中软键盘后面的 Autocompletetextview 下拉菜单

Autocompletetextview dropdown behind soft keyboard in dialog fragment

我的应用程序中有一个对话框片段,里面有一个 autocompletetextview,但是下拉列表没有与软键盘的顶部对齐,而是放在后面,无法访问某些项目.

布局如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:padding="10dp"
    android:orientation="horizontal"
    android:windowSoftInputMode="adjustPan|adjustResize">

    <android.widget.AutoCompleteTextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:id="@+id/customDialogAtocompleteTextview"
        android:layout_weight=".7"
        android:layout_gravity="top" />

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight=".3">
        <Button
            android:id="@+id/customDialogBtOk"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Aceptar"/>
        <Button
            android:id="@+id/customDialogBtSearch"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Buscar"/>
        <Button
            android:id="@+id/customDialogBtMore"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Mas"/>
    </LinearLayout>

</LinearLayout>

那么我怎样才能让它与键盘对齐?

理论上说 android:windowSoftInputMode="adjustPan|adjustResize" 应该这样做,但由于某种原因它不这样做,所以你必须以编程方式做同样的事情:

getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

奇迹发生了!!!

[更新] 在我的例子中.. 因为我使用 bottomShetDialogFragment 内部自动完成。下拉不显示是因为我没有为自动完成设置下拉锚点。 只需添加 android:dropDownAnchor="@id/layout_above_this_autocomplete" 即可完美运行

您的 style.xml

中的广告新闻样式
<style name="AppBottomSheetDialogTheme" parent="Theme.Design.Light.BottomSheetDialog">
    <item name="bottomSheetStyle">@style/AppModalStyle</item>
    <item name="android:windowIsFloating">false</item>
    <item name="android:windowSoftInputMode">adjustResize</item>
</style>
<style name="AppModalStyle" parent="Widget.Design.BottomSheet.Modal">
<item name="behavior_peekHeight">400dp</item>

</style>

在你的 bottomshetdialog framgnet 中。 oncreate -> setStyle(DialogFragment.STYLE_NORMAL, R.style.AppBottomSheetDialogTheme)

override fun getTheme(): Int {
    return R.style.AppBottomSheetDialogTheme
}