出于某种原因,无论我做什么,AutoCompleteTextView中显示的文本始终为白色。我在XML中将textColor显式设置为黑色。我想知道android.R.layout.simple_list_item_1默认情况下是白色吗?
[这里是我设置ArrayAdapter的位置:
final ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_1, strings);
AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.searchUserTextField);
textView.setAdapter(adapter);
这是我的XML:
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="65dp"
android:background="@drawable/edittext_border"
android:layout_gravity="top"
android:textColor="#000000"
android:hint="@string/search_user"
android:id="@+id/searchUserTextField"
android:ems="150"
android:paddingLeft="25dp"
android:paddingTop="10dp"
android:paddingRight="10dp"
android:paddingBottom="10dp"
android:maxLines ="4"
android:maxLength ="150"
android:scrollHorizontally="false"
android:typeface="sans"
android:textSize="14sp"
android:fontFamily="sans-serif-light"
android:capitalize="none"
android:inputType="textEmailAddress"
android:gravity="center_vertical"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toLeftOf="@+id/submitSearch"
android:layout_toStartOf="@+id/submitSearch" />
看起来像是AOSP中已记录的错误。您可以在本文AutoCompleteTextview Color set white by default
中找到更多信息以及解决方法添加,以防有人仍在寻找可以解决问题的答案,因为它不是错误,但是您可以按如下所示为自动完成建议提供自定义布局:
更改此行代码
final ArrayAdapter<String> adapter = new ArrayAdapter<String (getApplicationContext(), android.R.layout.simple_list_item_1, strings);
to
final ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.custom_autocomplete, strings);
将布局资源文件作为custom_autocomplete.xml,并提供所需的设置。工作模板
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="@color/colorPrimary"
android:background="@color/white"
android:paddingHorizontal="10dp"
android:paddingVertical="15dp" />