android AutoCompleteTextView 白底白字下拉列表

发布于 2024-11-01 20:32:09 字数 534 浏览 6 评论 0原文

在这里打破了我的头,我在网上搜索了很多,这似乎是 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 资源(按预期工作,白色背景上的黑色文本),但没有找到使其工作的方法,继续获得相同的结果

有帮助吗?

breaking my head here, i have searched online for quite a bit and it seems this was a bug on android before but have not found a solution yet.

I have a AutoCompleteTextView:

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

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

autodesignations.setAdapter(adapterShapes);

the widget works, but the dropdown text is always white text on white background.

I have tried setting the resource for the adapter to several combinations of android's built-in layouts & also my own.

Even pointing it to a TextView resource being also use for a Spinner (which works as expected, black text on white background), but have found no way of making this work, keep getting the same results

Any help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

耳钉梦 2024-11-08 20:32:09

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

I had this issue . Fixed it using android.R.layout.select_dialog_item for layout.

孤独岁月 2024-11-08 20:32:09

这是我的问题的答案。

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

因此,我将在 onCreate() 期间通过 getApplicationContext(); 检索“context”的行(包含在 onClickListener 中)更改

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 回调之外测试了它,并注意到两件事:

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

希望它对其他人有帮助。

So here is the answer for my issue.

As often, this and a context reference are not exactly the same. Maybe because the context reference might be passed down across some activities, whatever.

So I changed that line (which is included inside a onClickListener) where 'context' is retrieved during onCreate() by getApplicationContext();

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

into the following line where I used a this from my class :

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

And it works ! No more white font.

I tested it outside the onclicklistener callback and noticed 2 things :

  • using same 'context' variable did make the drop down to be displayed in white
  • sticking to 'this' avoids the issue.

Hope it helps someone else.

南烟 2024-11-08 20:32:09

很奇怪......我有 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" />

您可能应用了某种类型的主题吗?

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

Very odd... I have AutoCompleteTextView's that work just fine. I found the size of the drop down entries was much too large so I ended up setting my own resource layout file. Stupid question... did you set the textColor in your xml?

Here's one I use...

<?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" />

Do you have some type of theme applied perhaps?

Also... perhaps the text isn't white, but instead you accidentally have empty strings?

吃颗糖壮壮胆 2024-11-08 20:32:09

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

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

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

I tried setting up the theme before setcontext, tried different resources parameter in arrayAdapter and tried different theme ,but nothing helped.

Then I changed the context from 'this' to 'getApplicationContext' but the problem was persistent.

Finally I changed the context parameter to "getBaseContext()" and the problem was solved.

把人绕傻吧 2024-11-08 20:32:09

这是您的答案

 SimpleCursorAdapter ad = new SimpleCursorAdapter(this, android.R.layout.simple_dropdown_item_1line, null,
                new String[] { "item_Name" }, new int[] {android.R.id.text1} , 2 );

Here is your answer

 SimpleCursorAdapter ad = new SimpleCursorAdapter(this, android.R.layout.simple_dropdown_item_1line, null,
                new String[] { "item_Name" }, new int[] {android.R.id.text1} , 2 );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文