AutoCompleteTextview 颜色默认设置为白色
我在我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
好吧,我们无法设置“建议文本”颜色,但我们可以更改其背景!只需使用
android:popupBackground="YOUR_COLOR_HEX"
即可,如本例所示:也适用于 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:Works also on Lollipop! ;)
你应该使用
setTheme(android.R.style.Theme);
beforesetContentView
它对我有用:)
You should use
setTheme(android.R.style.Theme);
beforesetContentView
It worked for me :)
设置弹出窗口的背景颜色为
city.setDropDownBackgroundResource(R.color.indicator);
Set background color of pop up as
city.setDropDownBackgroundResource(R.color.indicator);
如果有人仍然遇到同样的问题
这对我有用
if anyone still have the same issue
This worked for me
将其添加到您的主题中:
Add this to your theme:
这对我有用 首先使用这个 before setContentView()
你必须改变值文件夹中的colors.xml中的一些颜色
This worked for me First use this before setContentView()
you have to change some colors in colors.xml in the values folder
这是一个已记录的错误,
您可以在同一链接中找到一些方法来修复它。
自动完成文本视图错误
错误解决方案
注意:此解决方案不适用于
棒棒糖
我希望它有帮助......
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...
我尝试在 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.
对于 Lollipop,所报告的 bug 将不起作用。
我最终通过使用
android.R.layout.simple_spinner_dropdown_item
和adapter
作为以下:这将解决白色文本问题,无需更改主题属性或任何内容。
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 usingandroid.R.layout.simple_spinner_dropdown_item
with theadapter
instead as the following:This will solve the White text issue without any need to change Theme attributes or anything.
您可以在
ArrayAdapter
中使用simple_list_item_1
,另一种解决方案是退出
AndroidManifest.xml
中的样式NOTE:此解决方案不适用于
lollipop
操作系统版本You can use
simple_list_item_1
inArrayAdapter
,Another solution is to quit the style in
AndroidManifest.xml
NOTE: This solution does not work with
lollipop
OS versions