how to change checkbox color in android

how to change checkbox color in android

To change the color of a checkbox in Android, you can use the setButtonTintList method of the CompoundButton class.

Here's an example of how you might do this in an activity:

import android.graphics.Color;
import android.graphics.PorterDuff;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.CheckBox;

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        CheckBox checkBox = findViewById(R.id.checkbox);
        checkBox.getBackground().setColorFilter(Color.RED, PorterDuff.Mode.SRC_ATOP);
        checkBox.setButtonTintList(ColorStateList.valueOf(Color.RED));
    }
}
Source‮ual.www:‬tturi.com

In this example, the setColorFilter method is used to set the color of the checkbox background, and the setButtonTintList method is used to set the color of the check mark itself. The colors are specified using the Color class.

You can use any valid color code to set the colors of the checkbox as desired.

Created Time:2017-11-01 12:05:13  Author:lautturi