Skip to content

Commit 17d1583

Browse files
Merge pull request #62 from manojdcoder/issue-59
Support radio button appearance in Android
2 parents 1537cb7 + 1024685 commit 17d1583

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

checkbox.android.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
Style,
1010
booleanConverter
1111
} from "tns-core-modules/ui/core/view";
12-
declare const android: any;
12+
declare const android: any, java: any;
1313

1414
export const checkedProperty = new Property<CheckBox, boolean>({
1515
name: "checked",
@@ -41,8 +41,14 @@ export const tintColorProperty = new CssProperty<Style, string>({
4141
}
4242
});
4343

44+
export const enum BoxType {
45+
Circle = 1,
46+
Square = 2
47+
}
48+
4449
export class CheckBox extends View implements CheckBoxInterface {
4550
private _android: any; /// android.widget.CheckBox
51+
private _boxType: number;
4652
private _checkStyle: string;
4753
private _checkPadding: string;
4854
private _checkPaddingLeft: string;
@@ -58,6 +64,14 @@ export class CheckBox extends View implements CheckBoxInterface {
5864
return this._android;
5965
}
6066

67+
set boxType(value: number) {
68+
this._boxType = value;
69+
}
70+
71+
get boxType() {
72+
return this._boxType;
73+
}
74+
6175
get checkStyle() {
6276
return this._checkStyle;
6377
}
@@ -115,7 +129,7 @@ export class CheckBox extends View implements CheckBoxInterface {
115129
return "";
116130
}
117131
[textProperty.setNative](value: string) {
118-
this.nativeView.setText(value);
132+
this.nativeView.setText(java.lang.String.valueOf(value));
119133
}
120134

121135
get fillColor(): string {
@@ -140,10 +154,11 @@ export class CheckBox extends View implements CheckBoxInterface {
140154
}
141155

142156
public createNativeView() {
143-
this._android = new android.support.v7.widget.AppCompatCheckBox(
144-
this._context,
145-
null
146-
);
157+
this._android = new android.support.v7.widget[
158+
this.boxType == BoxType.Circle
159+
? "AppCompatRadioButton"
160+
: "AppCompatCheckBox"
161+
](this._context, null);
147162
if (this.checkPaddingLeft) {
148163
this._android.setPadding(
149164
parseInt(this.checkPaddingLeft),

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nativescript-checkbox",
3-
"version": "2.1.12",
3+
"version": "2.1.13",
44
"description": "NativeScript plugin for checkbox widget.",
55
"main": "checkbox",
66
"typings": "index.d.ts",

0 commit comments

Comments
 (0)