android - AutoCompleteTextView 下拉列表中的项目不可见。如何改变他们的颜色..?

标签 android autocompletetextview

我制作了一个 AutoCompletetextView。 AutoCompleteTextView 下拉列表中的项目不可见。如何更改这些项目的颜色。

它是这样的:

enter image description here

最佳答案

为了控制在自动完成 View 中显示项目的方式,您必须在适配器中设置 textViewResourceId。您可以使用 ArrayAdapter 并将 android.R.layout.simple_dropdown_item_1line 作为 textViewResourceId,如下所示。

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line, yourList);
AutoCompleteTextView autocompleteView = (AutoCompleteTextView) findViewById(R.id.autocomplete_box);
autocompleteView.setAdapter(adapter);

如果您想为显示的项目创建自己的样式,请创建一个以 TextView 作为根元素的 XML(我们将其命名为 my_custom_dropdown.xml黑色文本和白色背景)

<?xml version="1.0" encoding="utf-8"?>
<TextView 
    xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:textSize="20sp" 
    android:padding="5sp"
    android:textColor="@color/black"
    android:background="@color/white"/>

然后如下引用适配器中的 xml -

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.my_custom_dropdown, yourList);

关于android - AutoCompleteTextView 下拉列表中的项目不可见。如何改变他们的颜色..?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11427528/

相关文章:

java - Eclipse 正在尝试在我的 .svn 目录中构建文件...我该如何告诉它停止?

android - 如何在日 View 中显示日历

android - AutoCompleteTextView 中的变音符号/国际字符

android - 如何在横向显示 AutoCompleteTextView 建议

android - 使用自定义数组适配器和过滤器重置自动完成 TextView

android - 添加 facebook sdk 后重复条目 : com/google/android/gms/internal/zzaa. 类

android - Fragment 到 Activity 过渡

android - 从一项 Activity 移至另一项 Activity 时,键盘会自动弹出

android - AutoCompleteTextView 在软键盘上的清晰焦点关闭

android - 简单的碰撞检测 - Android