在微调文字为白色在白色背景上 [英] Text on spinner is white on a white background

查看:143
本文介绍了在微调文字为白色在白色背景上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的纺纱厂的文字是白色的,而且我也不知道为什么。

The text on my spinners is white, and I have no idea why.

这是我的XML,没有什么特别的。

This is my xml, nothing special

 <Spinner
     android:id="@+id/spinner_date"
     android:layout_width="0dp"
     android:layout_height="wrap_content"
     android:layout_weight="1" />

和我的code

dateSpinner = (Spinner) findViewById(R.id.spinner_date);
selectedDate = calendar.getTime();
List<String> list = new ArrayList<String>();
list.add(formatter.format(selectedDate));
dateAdapter = new ArrayAdapter<String>(mContext,
            android.R.layout.simple_spinner_item, list);
dateSpinner.setAdapter(dateAdapter);

这可能是因为我的文字显示为白色的原因是什么?

What could be the reason that my text is displayed in white?

编辑: 我找到了原因,我换成这是一套在我的onCreate的mContext参数。

I've found the reason, I replaced the mContext parameter which was set in my onCreate.

mContext = getApplicationContext();

现在我用dateAdapter =新的ArrayAdapter(这一点,                 android.R.layout.simple_spinner_item,清​​单); 和它的作品。

Now I use dateAdapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, list); and it works.

推荐答案

我有同样的问题,已经找到了答案。你不使用的应用程序上下文,而是只使用 getActivity()(如果你在片段)或本(如果你在活动),它将工作

I have same problem and have found the answer. You dont use application context, instead, just use getActivity() (if you are in fragment) or this (if you are in activity), it will work

 dateAdapter = new ArrayAdapter<String>(**this**,
        android.R.layout.simple_spinner_item, list);

这篇关于在微调文字为白色在白色背景上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆