简体   繁体   English

对话框片段中软键盘后面的Autocompletetextview下拉列表

[英]Autocompletetextview dropdown behind soft keyboard in dialog fragment

I have a dialog fragment in my app with an autocompletetextview in it, but the drop-down list instead of align with the soft keyboard's top, is placed behind, not giving access to some of the items. 我的应用程序中有一个对话框片段,其中有一个autocompletetextview ,但是下拉列表而不是与软键盘的顶部对齐,而是放在后面,而不允许访问某些项。

Here is the layout: 这是布局:

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

So how can I make it to align with the keyboard? 那么如何使其与键盘对齐呢?

Theory says that android:windowSoftInputMode="adjustPan|adjustResize" should do this but for some reason it doesn't, so you have to do the same programmatically: 理论上说android:windowSoftInputMode="adjustPan|adjustResize"应该做到这一点,但是由于某些原因它不这样做,因此您必须以编程方式执行同样的操作:

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

Aand the magic happens!!! 魔术发生了!!!

[update] in my case.. cause i use bottomShetDialogFragment with autocomplete inside. 在我的情况下[更新] ..因为我在内部使用了具有自动完成功能的bottomShetDialogFragment。 drop down not show cause i not set dropdownanchor for autocomplete. 下拉列表不显示原因,因为我未将dropdownanchor设置为自动完成。 just add android:dropDownAnchor="@id/layout_above_this_autocomplete" and work perfect 只需添加android:dropDownAnchor="@id/layout_above_this_autocomplete"完美运行

ad news style in your style.xml 您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>

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

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

结果

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM