我的应用程序中有一个对话框片段,其中包含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);
Aaaaa和魔法发生了