1

I can not figure out how to change the background color of a checkbox in react native? I am from frontend background and have pretty little knowledge on Android. I am using react native CheckBox component and am not using any libraries for this purpose.

Surendra Pathak
  • 204
  • 2
  • 11
  • Let see this links and follow the steps given here. 1)https://stackoverflow.com/questions/41930297/how-to-change-background-of-android-checkbox 2)https://stackoverflow.com/questions/5854047/how-to-change-the-color-of-a-checkbox/36635925 – Rahul Kushwaha Jan 14 '19 at 05:18
  • I believe these solutions work. But they are speaking in some foreign language. Can the solution be interpreted in React Nativeish way? :P – Surendra Pathak Jan 14 '19 at 05:43

2 Answers2

0

Try this to change backgroud color of checkbox component

 <View style={{ backgroundColor:this.state.checked? 'red':'white'}}>
      <CheckBox value={this.state.checked} this.setState({ checked: !this.state.checked }) />
 </View>

Try to change change code natively

<CheckBox
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:buttonTint="@color/CHECK_COLOR" />

for v7 older API levels:

<android.support.v7.widget.AppCompatCheckBox 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    app:buttonTint="@color/COLOR_HERE" /> 
Niroshan Ranapathi
  • 3,007
  • 1
  • 25
  • 35
0

In order to do that if you have view you can use

int color = Color.TRANSPARENT;
Drawable background = view.getBackground();
if (background instanceof ColorDrawable)
color = ((ColorDrawable) background).getColor();

or you can use color palettes

https://material.io/design/color/the-color-system.html#color-usage-palettes

sourav pandit
  • 8,647
  • 2
  • 19
  • 17