如何改变微调字体颜色? [英] How to change the Spinner font color?

查看:121
本文介绍了如何改变微调字体颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,在Droid X手机,用户说,字体颜色原来是白色的微调,使其不可见,除非用户突出显示的项目。没有其他手机似乎都有这个问题。我会试图迫使字体是黑色的,看看有没有什么帮助。我该怎么办呢?

下面是如何我目前正在填充的微调。这似乎是 simple_spinner_item 上的Droid X的被打破。

 字符串spin_arry [] =新的String [str_vec.size()];
str_vec.copyInto(spin_arry);
ArrayAdapter适配器=
    新的ArrayAdapter(这一点,android.R.layout.simple_spinner_item,spin_arry);
 

解决方案

我要使用微调工程样品从Android SDK中的下一个code的例子。


code

首先,你需要创建你的自定义适配器,它会拦截创立意见下拉列表:

 静态类CustomArrayAdapter< T>扩展ArrayAdapter< T>
{
    公共CustomArrayAdapter(上下文CTX,T []对象)
    {
        超(CTX,android.R.layout.simple_spinner_item,对象);
    }

    //其他构造函数

    @覆盖
    公共查看getDropDownView(INT位置,查看convertView,父母的ViewGroup)
    {
        查看查看= super.getView(位置,convertView,父母);

        //我们知道simple_spinner_item有android.R.id.text1 TextView的:

        / *如果(isDroidX){* /
            TextView的文字=(TextView的)view.findViewById(android.R.id.text1);
            text.setTextColor(Color.RED); //选择你的颜色:)
        / *} * /

        返回查看;

    }
}
 

然后在你的code这样的创建适配器:

 的String [] spin_arry = getResources()getStringArray(R.array.Planets)。
 this.mAdapter =新CustomArrayAdapter< CharSequence的>(这一点,spin_arry);
 


说明:

由于 CustomArrayAdapter 知道我们采用Android内置的布局资源,它也知道该文本将被放置在的TextView id为 android.R.id.text1 。这就是为什么它可以拦截创建视图下拉列表中,改变文字颜色为任何颜色是必要的。


截图:

I'm having an issue with the Droid X phones where users say that the font color turns out to be white in the spinner, making it invisible unless the users highlight the items. No other phones seem to have this problem. I was going to try to force the font to be black to see if that helps. How can I do that?

Here's how I'm currently populating the spinner. It seems like the simple_spinner_item is broken on Droid X's.

String spin_arry[] = new String[str_vec.size()];
str_vec.copyInto(spin_arry);
ArrayAdapter adapter =
    new ArrayAdapter(this,android.R.layout.simple_spinner_item, spin_arry);

解决方案

I'm going to use Spinner project sample from Android SDK for next code examples.


Code:

First, you need to create you custom adapter which will intercept the creation of views in drop down list:

static class CustomArrayAdapter<T> extends ArrayAdapter<T>
{
    public CustomArrayAdapter(Context ctx, T [] objects)
    {
        super(ctx, android.R.layout.simple_spinner_item, objects);
    }

    //other constructors

    @Override
    public View getDropDownView(int position, View convertView, ViewGroup parent)
    {
        View view = super.getView(position, convertView, parent);

        //we know that simple_spinner_item has android.R.id.text1 TextView:         

        /* if(isDroidX) {*/
            TextView text = (TextView)view.findViewById(android.R.id.text1);
            text.setTextColor(Color.RED);//choose your color :)         
        /*}*/

        return view;

    }
}

Then you create adapter in your code like this:

 String [] spin_arry = getResources().getStringArray(R.array.Planets);        
 this.mAdapter = new CustomArrayAdapter<CharSequence>(this, spin_arry);


Explanation:

Because CustomArrayAdapter knows that we use android's built-in layout resource, it also knows that text will be placed in TextView with id android.R.id.text1. That's why it can intercept the creation of views in drop down list and change text color to whatever color is needed.


Screenshot:

这篇关于如何改变微调字体颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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