繁体   English   中英

如何在屏幕底部实现 AutoCompleteTextView?

[英]How can I achieve AutoCompleteTextView at bottom of the screen?

我试图在屏幕底部有一个 AutoCompleteTextView,但它的行为不一致且令人困惑。 我以某种方式实现了它,但我更改了一些我无法跟踪的代码,现在在打字时,下拉菜单覆盖了文本输入区域并在高度上被削减。 当键盘被关闭时,结果更接近我想要的,但它的高度仍然更短。 我想要实现的是屏幕截图中的蓝色区域

输入 abcd

滚动下拉列表

活动_主要:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/layout_main">


<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimary"
    android:id="@+id/h">

    <ImageView
        android:id="@+id/button_nav"
        android:layout_width="36dp"
        android:layout_height="36dp"
        android:layout_alignParentStart="true"
        android:scaleType="fitCenter"
        android:src="@drawable/ic_menu_white_48dp"
        android:layout_margin="16dp" />
    <TextView
        android:id="@+id/title"
        android:layout_width="match_parent"
        android:layout_height="68dp"
        android:layout_gravity="center"
        android:text="@string/app_name"
        android:textAlignment="center" />
</RelativeLayout>

<androidx.drawerlayout.widget.DrawerLayout
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/h"
    tools:openDrawer="start">



        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal"
            android:layout_marginBottom="8dp"
            android:gravity="bottom">
            <androidx.appcompat.widget.AppCompatAutoCompleteTextView
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="wrap_content"
                android:dropDownHeight="match_parent"
                android:id="@+id/edit_link_or_username"
                android:inputType="text|textUri"
                android:imeOptions="actionNext"
                android:hint="@string/hint_enter_link_or_username" />
            <FrameLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginEnd="4dp">
                <ImageButton
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    android:id="@+id/button_confirm"
                    android:src="@drawable/ic_search_white_48dp"
                    android:visibility="visible"/>
                <ProgressBar
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    android:id="@+id/progress_link_or_username"
                    android:visibility="invisible" />
            </FrameLayout>

        </LinearLayout>
    <com.google.android.material.navigation.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer"
        tools:visibility="gone" />
</androidx.drawerlayout.widget.DrawerLayout>

更新的 AutoCompleteTextView:

<androidx.appcompat.widget.AppCompatAutoCompleteTextView
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="wrap_content"
                android:id="@+id/edit_link_or_username"
                android:inputType="textAutoComplete"
                android:hint="@string/hint_enter_link_or_username" />

改变父身高:

android:layout_height="wrap_content"

在 OnCreate 中添加了此代码:

window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)

暂无
暂无

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

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