Você está na página 1de 22

CHECKBOX

Checkbox
code in
XML
<Checkbox
android:id=@+id/simpleCheckBo
x
android:layout_width=wrap_cont
ent
android:layout_height=wrap_con
tent
android:text=Simple
CheckBox />
Checkbox

A specific type of two-states button that


can be either checked or unchecked.
An on/off switch that can be toggled by the
user.
Used when presenting a group of selectable
options that are not mutually exclusive.
ATTRIBUTES OF A
CHECKBOX
id

An attribute used to uniquely identify a check box.

<Checkbox
android:id=@+id/simpleCheckBox
android:layout_width=wrap_content
android:layout_height=wrap_content
android:text=Simple CheckBox />
checked

Used to set the current state of a check box. The value


should be true or false where true shows the checked state
and false shows unchecked state of a check box. The default
value of checked attribute is false. We can also set the
current state programmatically.

<Checkbox
android:id=@+id/simpleCheckBox
android:layout_width=wrap_content
android:layout_height=wrap_content
android:text=Simple CheckBox
android:checked=true /> <--set the current state of
the checkbox--!>
gravity

An optional attribute which is used to control the alignment


of text in checkbox like left, right, center, top, bottom,
center, vertical, center, horizontal, etc.
<Checkbox
android:id=@+id/simpleCheckBox
android:layout_width=wrap_content
android:layout_height=wrap_content
android:text=Simple CheckBox
android:checked=true
android:gravity=right|center_vertical /> <!--gravity
of the checkbox--!>
text

Used to set the text in a checkbox.

<Checkbox
android:id=@+id/simpleCheckBox
android:layout_width=wrap_content
android:layout_height=wrap_content
android:text=Simple CheckBox
android:checked=true
android:text=Text Attribute of Check Box /> <!
displays text of the checkbox--!>
textColor

Used to set the text color of a checkbox. Color value is in


form of #argb, #rgb, or #aarrggbb.

<Checkbox
android:id=@+id/simpleCheckBox
android:layout_width=wrap_content
android:layout_height=wrap_content
android:text=Text is Red Color
android:textColor=#f00 <!red color for the text of
checkbox--!>
android:checked=true />
textSize

Used to set the size of text of a checkbox.

<Checkbox
android:id=@+id/simpleCheckBox
android:layout_width=wrap_content
android:layout_height=wrap_content
android:text=Text size Attribute Of Check Box
android:textColor=#00f
android:checked=false
android:textSize=20sp /> <!set the text size of
text in checkbox--!>
textStyle
Used to set the text style of the text of a checkbox.

<Checkbox
android:id=@+id/simpleCheckBox
android:layout_width=wrap_content
android:layout_height=wrap_content
android:text=Text Style Attribute Of Check Box
android:textColor=#44f
android:textSize=20sp
android:checked=false
android:textStyle=bold|italic /> <!set the text
style of text in checkbox--!>
background
Used to set the background of a checkbox.

<Checkbox
android:id=@+id/simpleCheckBox
android:layout_width=wrap_content
android:layout_height=wrap_content
android:text=Text size Attribute Of Check Box
android:textColor=#fff
android:textSize=20sp
android:textStyle=bold|italic
android:checked=true
android:background=#000 /> <!black
background for the background of checkbox--!>
padding

Used to set the padding from left, right, top or bottom.

paddingRight : set the padding from the right side of the


checkbox.
paddingLeft : set the padding from the left side of the
checkbox.
paddingTop : set the padding from the top side of the
checkbox.
paddingBottom : set the padding from the bottom side of
the checkbox.
padding : set the padding from all sides of the checkbox.
Checkbox
android:id=@+id/simpleCheckBox

android:layout_width=wrap_content

android:layout_height=wrap_content
android:text=Padding Attribute Of
Check Box
android:textColor=#44f
android:textSize=20sp
android:textStyle=bold|italic
android:checked=false
android:padding=30dp /> <!
30dp padding from all sides--!>

Você também pode gostar