nstudio / nativescript-checkbox

NativeScript plugin for checkbox UI component
Other
119 stars 56 forks source link

Add support to api < 21 on fillColor property #4

Closed plaviano closed 7 years ago

plaviano commented 8 years ago

I tried to change this checkbox color on an Android 4.3 and that's the error I got:

JS: EXCEPTION: Error: Uncaught (in promise): Error: java.lang.NoSuchMethodError: no method with name='setButtonTintList' signature='(Landroid/content/res/ColorStateList;)V' in class Landroid/widget/CompoundButton; JS: com.tns.Runtime.callJSMethodNative(Native Method) JS: com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:861) JS: com.tns.Runtime.callJSMethodImpl(Runtime.java:726) JS: com.tns.Runtime.callJSMethod(Runtime.java:712) JS: com.tns.Runtime.callJSMethod(Runtime.java:693) JS: com.tns.Runtime.callJSMethod(Runtime.java:683) JS: com.tns.gen.java.lang.Runnable.run(Runnable.java:10) JS: android.os.Handler.handleCallback(Handler.java:730) JS: android.os.Handler.dispatchMessage(Handler.java:92) JS: android.os.Looper.loop(Looper.java:137) JS: android.app.ActivityThread.main(ActivityThread.java:5103) JS: java.lang.reflect.Method.invokeNative(Native Method) JS: java.lang.reflect.Method.invoke(Method.java:525) JS: com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737) JS: com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) JS: dalvik.system.NativeStart.main(Native Method)

As I researched, this may be related to the APIversion, as the setButtonTintList method was added on API 21.

Can this plugin add the support to such a color change on API's < 21 or there is another way of doing such a change?

Thanks

bradmartin commented 8 years ago

Added sdk check to the method, try the latest release.

plaviano commented 8 years ago

On line 86 of checkbox.android.ts you must put that check too. I put the check as numbers, or something like that:

parseInt(device.sdkVersion) >= 21

But that check only prevents the exception, not changing the default black tint for this component.

There is some another way of changing the tint color on devices with sdk < 21?

Thanks

bradmartin commented 8 years ago

Added the API check to fillColor with 1.1.4 https://www.npmjs.com/package/nativescript-checkbox - I'll have to research coloring lower Android SDKs. With a quick search I didn't find much without getting into drawables and a lot of work, no simple methods for quick change. If you research and find something simple to implement I can handle it, but anything that's going to take a long time I won't have time to implement and don't plan to, I'll accept a PR to handle it if someone does submit something in the future though :+1:

plaviano commented 8 years ago

Yeah, that's my conclusion too. I'll research in my spare time and if I get something I'll do a PR in the project. Thanks for your attention :).

arma7x commented 7 years ago

According this link, (currently im using android 4.4.2). I change line 70 from android.widget.CheckBox(this._context, null); to android.support.v7.widget.AppCompatCheckBox(this._context, null); And the new background color is colorAccent value in styles.xml when checkbox is checked. Black is default background color before I change line 70

bradmartin commented 7 years ago

Adding this now: colors

Will be in 1.2.5 published soon. You'll want to make sure you uninstall old apps using the plugin, add the plugin again to your app, build, then run. Or you'll likely not have the correct plugin code running on the device.