2

There are some problem that I cannot solve by myself. I'm currently making a simple android app for my training that utilizes multiple checkbox's.

What I want to do is as the title says, change the color of the text of the checkbox when the the condition is setEnabled(true). I've searched through google but couldn't find the solution to it. I've added the sample code that I'm using below. Sonce, I'm a noob the help from the pro's means a lot to me.

public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { buttonView.setTextColor(Color.GREEN); buttonClicked.add(buttonView.getText() .toString()); buttonView.setTextSize(18); count += 1; Log.d("TAG","is checked = "+isChecked); if (count >= 7) { for (int i = 0; i < checkbox.length; i++) { String item = Integer.toString(i+1); if (buttonClicked.indexOf(item)>-1) { checkbox[i].setEnabled(true); Log.d("TAG",i+" = 2is checked = "+isChecked); // buttonView.setTextColor(Color.YELLOW); } else { Log.d("TAG",i+" = 3is checked = "+isChecked); checkbox[i].setEnabled(false); // buttonView.setTextColor(Color.RED); } } } } else { if (count <= 7) { for (int i = 0; i < checkbox.length; i++) { checkbox[i].setEnabled(true); // buttonView.setTextColor(Color.BLACK); } } count--; buttonClicked.remove(buttonView.getText() .toString()); buttonView.setTextSize(15); } 
2
  • are you searching for setChecked(boolean value)? Your question is not clear, Can you make it more clear, it will be very helpful for us to help you :) Commented Apr 6, 2015 at 9:25
  • Sorry for my poor dialog. The problem is that I cannot set the color of the text of the checkbox efficiently. For example, if I press more than 7 checkbox's, all of the checkboxes will have the black text color, however,in the current code I'm using, when I uncheck the checkbox, instead of the black color, the green color sets up. I find this difficult. In other words, I want to make all the colors of the text black when unchecked and also checkbox of the checked checkbox when unchecked. . Commented Apr 6, 2015 at 9:34

3 Answers 3

2

Create the selector xml and put that in /res/color/text_my_checked.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_checked="true" android:color="#00ff00"/> <item android:color="#000000"/> <!-- anything else --> </selector> 

And use that in layout file like this

 <CheckBox android:id="@+id/checkBox1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Check" android:textColor="@color/text_my_checked" android:checked="true" /> 
Sign up to request clarification or add additional context in comments.

Comments

0

You can change the textcolor of check box as follows ,

yourCheckBox.setTextColor(Color.GREEN); 

Comments

0

This is one option:

checkboxbutton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Checkbox b = (CheckBox)v; if (b.isChecked()) { //your code b.setTextColor(Color.GREEN); } else //your code b.setTextColor(Color.BLACK); } }); 

Also, you can choose color defined in color.xml file

b.setTextColor(getResources().getColor(R.color.blue)); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.