在 android AutoCompleteTextView 弹出窗口上添加填充
Adding padding on android AutoCompleteTextView popup
在过去的两个半小时里,我一直在尝试做一些非常简单的事情:更改 Android 的 AutoCompleteTextView 弹出窗口(显示自动完成选项的弹出窗口)中的填充。
我正在尝试这样做,因为我的应用程序中的项目具有文本的高度(我不确定为什么),所以我想让它更容易点击。但是我能找到的每一个想法都没有用。
因此,如果有人能发现这个问题或提供替代解决方案,我真的很高兴。
郑重声明,我使用的是 android studio,我已经删除了对 API 的支持(因为我的最小值 API 是 16),所以我的应用是仅使用 100% 原生度假村。
定义另一个只包含自动完成文本视图和按钮的相对布局。看看这个link
Android layout padding is ignored by dropdown
我刚刚找到了一种方法,我必须使用已经包含项目填充的文本视图制作自定义视图布局。然后我创建了一个使用此布局的自定义适配器。
布局是这样的
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:layout_margin="0dp"
android:paddingLeft="@dimen/thin_margin"
android:paddingRight="@dimen/thin_margin"
android:paddingTop="@dimen/list_1line_item_padding"
android:paddingBottom="@dimen/list_1line_item_padding"/>
并且在自定义适配器中只是在 getView 方法中使用了它
itemView = LayoutInflater.from(ctx).inflate(R.layout.list_1line_item, null);
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="20dp"
>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="@dimen/dp_15"
android:paddingBottom="@dimen/dp_15"
android:id="@+id/parentid">
<AutoCompleteTextView
android:id="@+id/address_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/light_gray_bg"
android:drawableRight="@drawable/icon_search_smaller"
android:gravity="center_vertical"
android:hint="Start typing location"
android:inputType="textCapWords"
android:popupBackground="@drawable/auto_location_popup_bg"
android:textColor="@color/black"
android:textColorHint="@color/dark_grey"
android:textSize="16sp"
android:visibility="visible"
android:dropDownWidth="wrap_content"
android:dropDownAnchor="@+id/parentid">/>
<requestFocus />
</RelativeLayout>
</RelativeLayout>
在过去的两个半小时里,我一直在尝试做一些非常简单的事情:更改 Android 的 AutoCompleteTextView 弹出窗口(显示自动完成选项的弹出窗口)中的填充。
我正在尝试这样做,因为我的应用程序中的项目具有文本的高度(我不确定为什么),所以我想让它更容易点击。但是我能找到的每一个想法都没有用。
因此,如果有人能发现这个问题或提供替代解决方案,我真的很高兴。
郑重声明,我使用的是 android studio,我已经删除了对 API 的支持(因为我的最小值 API 是 16),所以我的应用是仅使用 100% 原生度假村。
定义另一个只包含自动完成文本视图和按钮的相对布局。看看这个link
Android layout padding is ignored by dropdown
我刚刚找到了一种方法,我必须使用已经包含项目填充的文本视图制作自定义视图布局。然后我创建了一个使用此布局的自定义适配器。
布局是这样的
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:layout_margin="0dp"
android:paddingLeft="@dimen/thin_margin"
android:paddingRight="@dimen/thin_margin"
android:paddingTop="@dimen/list_1line_item_padding"
android:paddingBottom="@dimen/list_1line_item_padding"/>
并且在自定义适配器中只是在 getView 方法中使用了它
itemView = LayoutInflater.from(ctx).inflate(R.layout.list_1line_item, null);
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="20dp"
>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="@dimen/dp_15"
android:paddingBottom="@dimen/dp_15"
android:id="@+id/parentid">
<AutoCompleteTextView
android:id="@+id/address_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/light_gray_bg"
android:drawableRight="@drawable/icon_search_smaller"
android:gravity="center_vertical"
android:hint="Start typing location"
android:inputType="textCapWords"
android:popupBackground="@drawable/auto_location_popup_bg"
android:textColor="@color/black"
android:textColorHint="@color/dark_grey"
android:textSize="16sp"
android:visibility="visible"
android:dropDownWidth="wrap_content"
android:dropDownAnchor="@+id/parentid">/>
<requestFocus />
</RelativeLayout>
</RelativeLayout>