android AutoCompleteTextView 白底白字下拉列表
在这里打破了我的头,我在网上搜索了很多,这似乎是 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我有这个问题。使用 android.R.layout.select_dialog_item 进行布局修复了它。
I had this issue . Fixed it using android.R.layout.select_dialog_item for layout.
这是我的问题的答案。
通常,this 和上下文引用并不完全相同。也许是因为上下文引用可能会在某些活动中传递,无论如何。
因此,我将在 onCreate() 期间通过
getApplicationContext();
检索“context”的行(包含在 onClickListener 中)更改为以下行,其中我使用了类中的 this
:有效!不再有白色字体。
我在 onclicklistener 回调之外测试了它,并注意到两件事:
希望它对其他人有帮助。
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();
into the following line where I used a this from my class :
And it works ! No more white font.
I tested it outside the onclicklistener callback and noticed 2 things :
Hope it helps someone else.
很奇怪......我有 AutoCompleteTextView 工作得很好。我发现下拉条目的大小太大,因此我最终设置了自己的资源布局文件。愚蠢的问题...你在 xml 中设置了 textColor 吗?
这是我使用的一个...
您可能应用了某种类型的主题吗?
另外...也许文本不是白色的,而是您不小心有空字符串?
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...
Do you have some type of theme applied perhaps?
Also... perhaps the text isn't white, but instead you accidentally have empty strings?
我尝试在 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.
这是您的答案
Here is your answer