简体   繁体   English

在第一行微调器中更改文本颜色

[英]Change text color in first row of spinner

I have a spinner. 我有一个旋转器。 When user clicks on it a dialog box appears with several rows and text inside that rows to choose from. 当用户单击它时,会出现一个对话框,其中有多行和文本可供选择。 The default text inside spinner is Select facility . 微调器内的默认文本是Select facility And the first row text is the same ie select facility . 并且第一行文本是相同的,即select facility Now what I want is to change the text color in first row in spinner dialog box ie the color of select facility. 现在我想要的是在微调器对话框的第一行中更改文本颜色,即选择工具的颜色。

How can I achieve this? 我怎样才能做到这一点?

Here is the code where I believe I can change it. 这是代码,我相信我可以改变它。

if (position == 0 && hideFirstText) {
        ((TextView) convertView).setText(R.string.select_facility);
        convertView.setBackgroundResource(R.color.light_green);
        return convertView;
    }

Here is what I already tried 这是我已经尝试过的

            ((TextView) convertView).setTextColor(4737352);

But above solution completely removes the first row text. 但上面的解决方案完全删除了第一行文本。

I also tried this 我也尝试过这个

    convertView.setTextColor(4737352);

But convertView does not have setTextColor() method. 但是convertView没有setTextColor()方法。

you should override the getView method,,like this 你应该覆盖getView方法,就像这样

@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
TextView text = (TextView) view.findViewById(R.id.spinner);
text.setTextColor(Color.RED);
return view;
}

when dialog opens it internally calls getDropDownView so customize this method of your adapter like this 当对话框打开时,它在内部调用getDropDownView,所以自定义这个适配器的方法

public View getDropDownView (int position, View convertView, ViewGroup parent){
        View row=super.getView(position, convertView, parent);
        if(position == 0){
            //Do custom stuff here like find textview & change textcolor
        }
        return(row);
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM