Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

Custom rendering of a Droid checkbox

$
0
0

I need to change the default border color of an Android check box. According to http://stackoverflow.com/questions/26447709/how-to-set-checkbox-border-color one should use android:buttonTint for this purpose. However, that seems only to be applicable if one is defining the layout (the checkbox) in an Android xml layout file.

I would like to do this in a custom renderer like:

protected override void OnElementChanged(ElementChangedEventArgs<CheckBox> e)
        {
            base.OnElementChanged(e);

            if (this.Control == null)
            {
                var checkBox = new Android.Widget.CheckBox(this.Context);
        /* and here change the border color of the checkbox */

I can set the background resource with something like:

checkBox.SetBackgroundResource(IsbApp.Droid.Resource.Drawable.CheckBox);

where CheckBox.xml looks like:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

  <solid android:color="#ffffff" >
  </solid>

  <stroke
      android:width="2dp"
      android:color="#ff0000" >
  </stroke>
  <corners android:radius="5dp" />
</shape>

but that changes the border color of the whole control, including the text which is associated with the checkbox.

I need to change the border color of only the part that is around the check mark itself.


Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>