AutoCompleteTextView 的下拉列表有项目,但它们不可见
Dropdown for AutoCompleteTextView has items but they are not visible
我正在使用 AutoCompleteTextView 组件来过滤成员数据。我在我的布局文件中设置如下
<AutoCompleteTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/autocomplete_swap_pool"
android:layout_width="match_parent"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:layout_height="@dimen/nfl_my_listings_and_my_bids_spinner_height"
android:layout_toLeftOf="@id/icon_on"
android:dropDownSelector="@color/black"
android:dropDownVerticalOffset="5dp"
android:dropDownWidth="wrap_content"
android:inputType="textAutoComplete|textAutoCorrect"
android:popupBackground="@color/white"
android:ems="10"
android:text="" />
然后我在我的代码中像这样初始化它
autoTextView = (AutoCompleteTextView) EngineGlobals.iRootActivity.findViewById(R.id.autocomplete_swap_pool);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(EngineGlobals.iApplicationContext, android.R.layout.simple_dropdown_item_1line, Cards);
autoTextView.setThreshold(1);
autoTextView.setAdapter(adapter);
当我输入文本时,会出现下拉框,但项目不可见,但它们在那里,因为如果我单击下拉框,项目就会出现。看起来好像是白底白字
我做错了什么?
我认为您需要将 textColor
应用到您的 hint
。为此,您需要为 AutoCompleteTextView
.
自定义行 layout
hint_item.xml
<TextView
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:textColor="@android:color/holo_green_dark" />
YourActivity.java
AutoCompleteTextView autoTextView = (AutoCompleteTextView) findViewById(R.id.autocomplete_swap_pool);
ArrayAdapter<String> autoadapter = new ArrayAdapter<String>(this, R.layout.hint_item, new String[]{"One", "Two", "Three"});
autoTextView.setAdapter(autoadapter);
输出
我正在使用 AutoCompleteTextView 组件来过滤成员数据。我在我的布局文件中设置如下
<AutoCompleteTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/autocomplete_swap_pool"
android:layout_width="match_parent"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:layout_height="@dimen/nfl_my_listings_and_my_bids_spinner_height"
android:layout_toLeftOf="@id/icon_on"
android:dropDownSelector="@color/black"
android:dropDownVerticalOffset="5dp"
android:dropDownWidth="wrap_content"
android:inputType="textAutoComplete|textAutoCorrect"
android:popupBackground="@color/white"
android:ems="10"
android:text="" />
然后我在我的代码中像这样初始化它
autoTextView = (AutoCompleteTextView) EngineGlobals.iRootActivity.findViewById(R.id.autocomplete_swap_pool);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(EngineGlobals.iApplicationContext, android.R.layout.simple_dropdown_item_1line, Cards);
autoTextView.setThreshold(1);
autoTextView.setAdapter(adapter);
当我输入文本时,会出现下拉框,但项目不可见,但它们在那里,因为如果我单击下拉框,项目就会出现。看起来好像是白底白字
我做错了什么?
我认为您需要将 textColor
应用到您的 hint
。为此,您需要为 AutoCompleteTextView
.
layout
hint_item.xml
<TextView
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:textColor="@android:color/holo_green_dark" />
YourActivity.java
AutoCompleteTextView autoTextView = (AutoCompleteTextView) findViewById(R.id.autocomplete_swap_pool);
ArrayAdapter<String> autoadapter = new ArrayAdapter<String>(this, R.layout.hint_item, new String[]{"One", "Two", "Three"});
autoTextView.setAdapter(autoadapter);
输出