21

在这里打破我的头,我在网上搜索了很多,这似乎是之前android上的一个错误,但还没有找到解决方案。

我有一个 AutoCompleteTextView:

autodesignations = (AutoCompleteTextView) findViewById(R.id.main_autocomp);

adapterShapesAuto = new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line, shapes);

autodesignations.setAdapter(adapterShapes);

该小部件有效,但下拉文本始终是白色背景上的白色文本。

我尝试将适配器的资源设置为 android 的内置布局和我自己的几种组合。

即使将它指向一个也用于 Spinner 的 TextView 资源(按预期工作,白色背景上的黑色文本),但没有找到使它工作的方法,继续获得相同的结果

有什么帮助吗?

4

5 回答 5

21

我有这个问题。使用 android.R.layout.select_dialog_item 进行布局修复它。

于 2012-05-30T07:28:26.937 回答
3

所以这是我的问题的答案。

通常,this和上下文引用并不完全相同。也许是因为上下文引用可能会在某些活动中传递,无论如何。

因此,我更改了在 onCreate() 期间通过以下方式检索“上下文”的那一行(包含在 onClickListener 中)getApplicationContext();

adapterListModele = new ArrayAdapter<String>(context, android.R.layout.select_dialog_item, listModeleNom);

进入我在课堂上使用 this 的以下行:

adapterListModele = new ArrayAdapter<String>(AncestorVehicule.this, android.R.layout.select_dialog_item, listModeleNom);

它有效!没有更多的白色字体。

我在 onclicklistener 回调之外对其进行了测试,发现了两件事:

  • 使用相同的“上下文”变量确实使下拉菜单显示为白色
  • 坚持“这个”可以避免这个问题。

希望它可以帮助别人。

于 2014-12-19T17:00:47.007 回答
1

很奇怪...我有 AutoCompleteTextView 的工作得很好。我发现下拉条目的大小太大了,所以我最终设置了自己的资源布局文件。愚蠢的问题......你在你的xml中设置了textColor吗?

这是我用的一个...

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/text1"
    android:singleLine="true"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:padding="6dp"
    android:textColor="#000000"
    android:ellipsize="marquee" />

您是否应用了某种类型的主题?

另外...也许文本不是白色的,而是您不小心有空字符串?

于 2011-04-19T02:41:18.107 回答
1

我尝试在 setcontext 之前设置主题,在 arrayAdapter 中尝试了不同的资源参数并尝试了不同的主题,但没有任何帮助。

然后我将上下文从“this”更改为“getApplicationContext”,但问题仍然存在。

最后我将上下文参数更改为“getBaseContext()”,问题就解决了。

于 2015-02-14T16:10:28.083 回答
0

这是你的答案

 SimpleCursorAdapter ad = new SimpleCursorAdapter(this, android.R.layout.simple_dropdown_item_1line, null,
                new String[] { "item_Name" }, new int[] {android.R.id.text1} , 2 );
于 2015-07-06T15:28:34.517 回答