How To Change Text Color Of Dynamically Created Checkbox
I want to change the text color of dynamically created checkbox in android. Please guide
Solution 1:
CheckBoxchk=newCheckBox(this);
chk.setText("Testing");
chk.setTextColor(Color.BLUE);
or From color.xml
chk.setTextColor(getResources().getColor(R.color.blue));
Solution 2:
Here is how i used to add CheckBox
Dynamically to RadioGroup
.
CheckBoxmCheckBox=newCheckBox(this);
//mCheckBox.setText(String.format("%s",header));//mCheckBox.setId(index1);//mCheckBox.setLayoutParams(lp);// mCheckBox.setOnClickListener(this);//mCheckBox.setPadding(mCheckBox.getTotalPaddingLeft() + 10, 0, 0, 10);
mCheckBox.setTextColor(Color.GREEN);
in above code you can see how CheckBox Text Color is set and also you can refer it by it's id.
Solution 3:
This Code snippet may help ypu
CheckBox mCheckBox= newCheckBox(this);
mCheckBox.setTextColor(R.color.textcolor);
Solution 4:
If you want to change text color for checkbox you need to do it last thing, after methods like: setText(), setListener...
try {
mCheckBox.setTextColor(mContext.getResources().getColor(R.color.red, null));
} catch (NoSuchMethodError e) {
Log.d(TAG, e.toString());
}
Some old APIs will trigger NoSuchMethodError exception so it will be good to catch it. And don't forget to set your theme or go with null if so.
Post a Comment for "How To Change Text Color Of Dynamically Created Checkbox"