Android: How to change CheckBox size?
You just need to set the related drawables and set them in the checkbox:
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="new checkbox"
android:background="@drawable/my_checkbox_background"
android:button="@drawable/my_checkbox" />
The trick is on how to set the drawables. Here's a good tutorial about this.
Changing the size of a checkbox in android
From another question here on SO:
You just need to set the related drawables and set them in the checkbox:
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="new checkbox"
android:background="@drawable/my_checkbox_background"
android:button="@drawable/my_checkbox" />
The trick is on how to set the drawables. Here's a good tutorial about
this.
EDIT: Just to make it a bit more clear, you will need these files to make the tutorial work:
CheckBoxTestActivity.java:
import android.app.Activity;
import android.os.Bundle;
public class CheckBoxTestActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Checked CheckBox"
android:checked="true"/>
<CheckBox
android:id="@+id/checkBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Unchecked CheckBox" />
<CheckBox
android:id="@+id/checkBox3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/checkbox_background"
android:button="@drawable/checkbox"
android:text="New Checked CheckBox"
android:checked="true"/>
<CheckBox
android:id="@+id/checkBox4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/checkbox_background"
android:button="@drawable/checkbox"
android:text="New Unchecked CheckBox" />
</LinearLayout>
checkbox.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_checked="false"
android:drawable="@drawable/checkbox_off_background"/>
<item
android:state_checked="true"
android:drawable="@drawable/checkbox_on_background"/>
</selector>
checkbox_background.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@drawable/btn_check_label_background" />
</selector>
and btn_check_label_background.9.png, checkbox_off_background.png and checkbox_on_background.png from the tutorial page.
How to change the size of the button of an android checkbox?
I solved it by making the bitmaps the right size. I cannot scale it now but I tested it on several devices with varying dpi settings and it seems fine. For now.
Change the size of android Checkbox
The path for themes.xml and styles.xml is changed from the given one to android-sdk-windows\platforms\android-8\data\res\values
(android-8 is for API-level 8).
The drawable btn_check.xml is available at android-sdk-windows\platforms\android-8\data\res\drawable
, while the other drawable components are available at respective hdpi / mdpi folders.
2) You simply need to include the respective drawables of the checkbox in different states (i.e. focused, pressed, checked, or normal), and a drawable for the background as well (often the nine-patch file given in the link).
Include these in the respective xml to specify the looks of the checkbox as given in the link, and include that xml in the android:button
and android:background
attributes of your checkbox. That should do it all...! :)
how to change the border size(thickness) of checkbox in android kotlin?
<CheckBox
android:scaleX="0.70"
android:scaleY="0.70"
...
/>
Try this, above API level 11
Checkbox Size Xamarin Android
Maybe I found a possible solution, check the steps below:
- Add a
BindableProperty
calledSizeRequest
in the custom CheckBox control. - Create a method
GetDefaultCheckBoxDrawable
to get the default CheckBox drawable. - Change
OnElementChanged
method to clear and resize the text, set the width/height based onSizeRequest
, reset the button drawable and set a new Background drawable with the default checkbox drawable.
AndroidCheckboxRenderer.cs
:
private Drawable GetDefaultCheckBoxDrawable(Android.Views.View view)
{
TypedValue value = new TypedValue();
view.Context.Theme.ResolveAttribute(Android.Resource.Attribute.ListChoiceIndicatorMultiple, value, true);
var origImg = view.Context.Resources.GetDrawable(value.ResourceId);
var porterDuffColor = new Android.Graphics.PorterDuffColorFilter(Element.CheckColor.ToAndroid(), Android.Graphics.PorterDuff.Mode.SrcIn);
origImg.SetColorFilter(porterDuffColor);
return origImg;
}
protected override void OnElementChanged(ElementChangedEventArgs<CustomCheckbox> e)
{
...
// CheckBox displays its height from the TEXT, as well as images.
checkBox.Text = "";
checkBox.SetTextSize(Android.Util.ComplexUnitType.Sp, 0);
// Set the width and height based on SizeRequest
if (Element.SizeRequest >= 0)
{
checkBox.SetWidth((int)Element.SizeRequest);
checkBox.SetHeight((int)Element.SizeRequest);
}
// Reset the Button Drawable
checkBox.SetButtonDrawable(null);
// Set Background Drawable with the default CheckBox
checkBox.SetBackgroundDrawable(GetDefaultCheckBoxDrawable(this));
...
}
Check out my GitHub for the full solution.
I hope this can help you.
Related Topics
How to Implement Drag and Drop in Android 2.2
Low-Latency Audio Playback on Android
Difference Between APK (.Apk) and App Bundle (.Aab)
Toolbar Overlapping Below Status Bar
How to Set Android_Sdk_Home Environment Variable
Pathpattern to Match File Extension Does Not Work If a Period Exists Elsewhere in the File Name
Volley JSONobjectrequest Post Parameters No Longer Work
Gradle Failed to Resolve Library in Android Studio
How to Store a Boolean Value Using Sharedpreferences in Android
Eclipse Reports Rendering Library More Recent Than Adt Plug-In
Refresh Fragment UI from Fragmentactivity
How to Make Custom Dialog with Rounded Corners in Android
Android: Getting "Manifest Merger Failed" Error After Updating to a New Version of Gradle
What Is the Intent of the Methods Getitem and Getitemid in the Android Class Baseadapter
Is There a Simple Example of the Popupwindow Class Using Android V2.0