当行backgroundcolor设置时,TextColor不显示

时间:2012-11-11 22:26:49

标签: android

如果我的行为红色,则文本不会设置为绿色和粗体斜体。调试时,我可以看到它告诉TextView设置每个textViews设置。

TableRow row = new TableRow(getContext());
            row.setLayoutParams(new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
            String[] items = list.get(l).split(":");
            for(int i=0; i < items.length; i++){
                //see if i need to colour row
                if(items[i].startsWith("colorme_") == true) {
                    if (items[i].substring(8).equals("red") == true) {
                        row.setBackgroundColor(Color.RED);
                    }
                } else { 
                    //create a temp textview then add to row
                    TextView tempTV = new TextView(getContext());
                    tempTV.setText(items[i].toString());
                    //test against correct answers and colour text view green if correct
                    if (correctAnswers != null && correctAnswers.size() > i) {
                        if (correctAnswers.get(i).equals(items[i].toString()) == true) {
                            tempTV.setTextColor(Color.GREEN);
                            tempTV.setTypeface(null, Typeface.BOLD_ITALIC);
                        }                               
                    }
                    row.addView(tempTV,lpTextView); 
                }
            }
            //add the row
            tempTable.addView(row);

1 个答案:

答案 0 :(得分:1)

对我来说,看起来你已经在if else的不同侧面分隔了两个不同的颜色设置代码,因此它们不会同时被调用,因为如果if语句返回是的,那么else语句将不会被触发,你将传递setTextColor代码而不运行它,反之亦然,如果if语句返回false,那么你将跳过更改背景颜色并仅更改文本颜色。

希望有意义

这里编辑是一个例子

if(items[i].startsWith("colorme_") == true) {
    //this is where your are preforming your change row color to red
} else{
    //this is where you are setting your text color to green
}