I'm trying to change the size of the Android checkbox in an Xamarin Forms application. First some background. I setup a custom control in Xamarin Forms for the checkbox that looks like:
public class CheckBox : View
{
public static readonly BindableProperty IsCheckedProperty =
BindableProperty.Create(nameof(IsChecked), typeof(bool), typeof(CheckBox), false, propertyChanged: IsCheckedChanged);
// Other properties...
}
In the Android project I have the renderer that looks like:
[assembly: ExportRenderer(typeof(CheckBox), typeof(CheckBoxRenderer))]
namespace SmallVictories.Droid.Controls
{
internal class CheckBoxRenderer : ViewRenderer<CheckBox, Android.Widget.CheckBox>
{
protected override void OnElementChanged(ElementChangedEventArgs<CheckBox> e)
{
if (Control == null)
{
_nativeControl = new Android.Widget.CheckBox(Context);
SetNativeControl(_nativeControl);
}
// Other setup...
}
}
}
I then use the checkbox on page as so:
<StackLayout Orientation="Horizontal" BackgroundColor="White" Padding="5" Margin="0" HorizontalOptions="FillAndExpand">
<controls:CheckBox HorizontalOptions="Start" WidthRequest="25" HeightRequest="25" />
If I make the width and height smaller then 25 then the checkbox gets clipped.
If I make the width and height larger then 25 the checkbox stays the same size but the clickable area gets bigger. Below is the checkbox size set to 35 but it's the same size as when set to size of 25.
I've tried adjusting things such as size on the native control and also the layout parameters. Didn't work.
// Neither of these work.
_nativeControl.SetWidth(35);
_nativeControl.SetHeight(35);
var lp = _nativeControls.LayoutParameters;
lp.Width = 35;
lp.Height = 35;
_nativeControls.LayoutParameters = lp;
Any other suggestions on what I can try? Thanks.