微调文字的颜色是白色的? [英] spinner text color is white?
问题描述
我用微调的布局中。 我用这个code:
...
<微调
机器人:layout_width =200dp
机器人:layout_height =WRAP_CONTENT
机器人:ID =@ + ID / spin_prod_promo/>
...
现在,当我给它的适配器,我用这个code:
...
ArrayAdapter<字符串> DataAdapter的=新的ArrayAdapter<字符串>(mcontext,android.R.layout.simple_spinner_item,mylabels);
//下拉布局样式
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
微调myspinner =(微调)V.findViewById(R.id.spin_prod_promo);
//连接数据适配器微调器
myspinner.setAdapter(DataAdapter的);
...
我的问题是,微调的文本颜色是白色的......因此不可读的,我不将其设置为这种方式在code的任何地方。
在有趣的事情是,我使用完全相同的code在不同的活动和Spinner具有正确的颜色。 所不同的是,在这个(BAD)的情况下的旋转器位于一个片段。
- 因此,如果微调是一个活动 - 颜色都很好
- 如果微调位于片段 - 颜色搞砸
我试着用了微调的项目自定义布局,但我成功是使微调照看残疾。另外还有总是有背景的颜色下拉一个项目(它只能待观察,如果我点击它,那么我只要能看到的内容,我不断的点击) 这里发生了什么? 我该如何解决这个问题呢?
有什么我可以做的设置微调的颜色为主题的颜色? 片段中的所有其他部件有正常的颜色...
感谢您
上下文mcontext = getActivity()getApplicationContext()。这是错的?
是的,这是错误的。仅使用 getApplicationContext()
时,你知道的正是为什么您正在使用 getApplicationContext()
。特别是,不要使用 getApplicationContext()
的充气布局,因为它会搞砸不使用正确的主题。
我会删除 mcontext
完全与替换它getActivity()
,其中需要在你的片段。
I use a Spinner inside a layout. I use this code:
...
<Spinner
android:layout_width="200dp"
android:layout_height="wrap_content"
android:id="@+id/spin_prod_promo" />
...
Now, when I assign it's adapter I use this code:
...
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(mcontext, android.R.layout.simple_spinner_item, mylabels);
// Drop down layout style
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
Spinner myspinner = (Spinner) V.findViewById(R.id.spin_prod_promo);
// attaching data adapter to spinner
myspinner.setAdapter(dataAdapter);
...
My problem is that, the text color of the spinner is white... thus unreadable, and I do not set it to be this way anywhere in the code.
The "funny thing" is that I use the exact same code in a different activity and the Spinner has the right colors. The difference is that in this (BAD) case the spinner is located in a fragment.
- So if the spinner is in an activity - colors are fine
- If the spinner is located on a fragment - color is messed up
I tried using a custom layout for the items of the spinner, but all I succeeded was to make the spinner look disabled. Plus there is always an item in the dropdown that has the color of the background (it can only be seen if I click on it, then I can see the content as long as I keep the click on) What is going on here? How can I solve this problem?
Is there something I can do to set the colors of the spinner to be the colors of the theme? All other widgets in the fragment have normal colors...
Thank you
Context mcontext = getActivity().getApplicationContext(); Is this wrong?
Yes, this is wrong. Only use getApplicationContext()
when you know exactly why you are using getApplicationContext()
. In particular, never use getApplicationContext()
for inflating layouts, as it will screw things up by not using the right theme.
I would delete mcontext
entirely, replacing it with getActivity()
where needed in your fragment.
这篇关于微调文字的颜色是白色的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!