Maveňツ
Maveňツ

Reputation: 1

how to change checkbox color to black

I have implemented checkbox programtically via for loop, how to change them to black color since other textviews are in black color its lucking odd, they are not in the xml ... there is one linear layout where these are getting added.

for (int i = 0; i < list_sted.size(); i++) {
            CheckBox cb = new CheckBox(getApplicationContext());
            cb.setText(""+list_sted.get(i));
            cb.setTextColor(R.color.Black);
            cb.setTextAppearance(getBaseContext(), android.R.attr.checkboxStyle);
            checkbox_lay.addView(cb);
        }

enter image description here

Upvotes: 0

Views: 319

Answers (2)

Piyush
Piyush

Reputation: 18933

You can't do this.

cb.setTextColor(R.color.Black);

Use this one.

cb.setTextColor(Color.BLACK);

or

cb.setTextColor(Color.parseColor("#000000"));

Upvotes: 3

Himanshu Agarwal
Himanshu Agarwal

Reputation: 4683

Try using this:

cb.setTextColor(Color.BLACK);

or From color.xml

cb.setTextColor(getResources().getColor(R.color.black));  

Upvotes: 0

Related Questions