AutoCompleteTextview 颜色默认设置为白色

发布于 2024-12-20 15:08:29 字数 771 浏览 2 评论 0原文

我在我的 Android 应用程序中使用了 AutoCompleteTextView,它工作正常。我面临的唯一问题是建议的颜色默认为白色,即我看不到任何建议。因此,当我开始输入某些内容时,列表会扩展为白色条目(不可见),但是当我单击任何项​​目时,我发现它正在正常工作。似乎只有颜色是问题。我正在使用以下代码。

<AutoCompleteTextView android:id="@+id/location"  android:textColor="#000000"
            android:layout_width="fill_parent" android:layout_height="wrap_content"></AutoCompleteTextView>

谁能

 ArrayAdapter<String> autoadapter=new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line,cities);
            city = (AutoCompleteTextView) findViewById(R.id.location);
            city.setAdapter(autoadapter);
            city.setThreshold(1);
            city.setTextColor(Color.BLACK);

告诉我问题是什么?
-提前致谢

I used an AutoCompleteTextView in my android app and it is working correctly. The only problem I am facing is that the color of the suggestions is white by default that is i am not able to see any suggestions. So when i start typing something the list expands with white entries(invisible), but when i click on any item i find that it is working as it should be. Only the color seems to be the problem. I am using the following code.

<AutoCompleteTextView android:id="@+id/location"  android:textColor="#000000"
            android:layout_width="fill_parent" android:layout_height="wrap_content"></AutoCompleteTextView>

and

 ArrayAdapter<String> autoadapter=new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line,cities);
            city = (AutoCompleteTextView) findViewById(R.id.location);
            city.setAdapter(autoadapter);
            city.setThreshold(1);
            city.setTextColor(Color.BLACK);

Can anyone please tell me what the problem is??
-Thanks in advance

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

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

发布评论

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

评论(10

不弃不离 2024-12-27 15:08:30

好吧,我们无法设置“建议文本”颜色,但我们可以更改其背景!只需使用 android:popupBackground="YOUR_COLOR_HEX" 即可,如本例所示:

<AutoCompleteTextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/autocompletetextview"
        android:layout_gravity="center_horizontal"
        android:hint=" ... "
        android:popupBackground="#000000"/>

也适用于 Lollipop! ;)

Well, we can't set the "suggestion text" color, but we can change its background! Just use android:popupBackground="YOUR_COLOR_HEX" as in this example:

<AutoCompleteTextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/autocompletetextview"
        android:layout_gravity="center_horizontal"
        android:hint=" ... "
        android:popupBackground="#000000"/>

Works also on Lollipop! ;)

も让我眼熟你 2024-12-27 15:08:30

你应该使用

setTheme(android.R.style.Theme); before setContentView

它对我有用:)

You should use

setTheme(android.R.style.Theme); before setContentView

It worked for me :)

野生奥特曼 2024-12-27 15:08:30

设置弹出窗口的背景颜色为city.setDropDownBackgroundResource(R.color.indicator);

Set background color of pop up ascity.setDropDownBackgroundResource(R.color.indicator);

中二柚 2024-12-27 15:08:30

如果有人仍然遇到同样的问题

这对我有用

autocompleteF.setBackgroundColor(color.black);

if anyone still have the same issue

This worked for me

autocompleteF.setBackgroundColor(color.black);
幽蝶幻影 2024-12-27 15:08:30

将其添加到您的主题中:

<item name="android:autoCompleteTextViewStyle">@style/Widget.AppCompat.AutoCompleteTextView</item>

Add this to your theme:

<item name="android:autoCompleteTextViewStyle">@style/Widget.AppCompat.AutoCompleteTextView</item>
爱的十字路口 2024-12-27 15:08:30

这对我有用 首先使用这个 before setContentView()

setTheme(android.R.style.TextAppearance_DeviceDefault_Medium_Inverse);

你必须改变值文件夹中的colors.xml中的一些颜色

This worked for me First use this before setContentView()

setTheme(android.R.style.TextAppearance_DeviceDefault_Medium_Inverse);

you have to change some colors in colors.xml in the values folder

无戏配角 2024-12-27 15:08:29

这是一个已记录的错误,

您可以在同一链接中找到一些方法来修复它。

自动完成文本视图错误

错误解决方案

注意:此解决方案不适用于棒棒糖

我希望它有帮助......

This a logged bug,

You can find some ways to fix it in the same link.

Auto complete text view bug

Bug solution

Note: This solution will not work with lollipop

I hope it helps...

尐偏执 2024-12-27 15:08:29

我尝试在 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-12-27 15:08:29

对于 Lollipop,所报告的 bug 将不起作用。

我最终通过使用 android.R.layout.simple_spinner_dropdown_itemadapter 作为以下:

ArrayAdapter<String> adapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_dropdown_item, suggestionList);

这将解决白色文本问题,无需更改主题属性或任何内容。

For Lollipop, all the work around solutions in the reported bug will not work.

I finally reached a solution that works with lollipop and the previous OS versions by using android.R.layout.simple_spinner_dropdown_item with the adapter instead as the following:

ArrayAdapter<String> adapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_dropdown_item, suggestionList);

This will solve the White text issue without any need to change Theme attributes or anything.

夜光 2024-12-27 15:08:29

您可以在ArrayAdapter中使用simple_list_item_1

ArrayAdapter<String> autoadapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,cities);
            city = (AutoCompleteTextView) findViewById(R.id.location);

另一种解决方案是退出AndroidManifest.xml中的样式

NOTE:此解决方案不适用于 lollipop 操作系统版本

You can use simple_list_item_1 in ArrayAdapter,

ArrayAdapter<String> autoadapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,cities);
            city = (AutoCompleteTextView) findViewById(R.id.location);

Another solution is to quit the style in AndroidManifest.xml

NOTE: This solution does not work with lollipop OS versions

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文