Android Switch compatibility libraries - theme sometimes not applied -
i'm using following switch open-source compatibility library:
https://github.com/ankri/switchcompatlibrary
so far works well, except on devices (last reported on android 4.0.4), app crashes first time activity (containing switch) opened! on following run works fine.
i've tried apply style (that includes switch style) in various ways, nothing seems solve it:
- in application tag
- in activity tag
- in oncreate() of activity containing switch
it's if on first run theme not applied , app crashes. on app restart same activity ok!?
there compatibility library tried, here: https://github.com/bod/android-switch-backport
but exact same results!
here stack trace when app crashes:
------------ java.lang.nullpointerexception @ de.ankri.views.switch.onmeasure(sourcefile:514) @ android.view.view.measure(view.java:12723) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:4704) @ android.widget.linearlayout.measurechildbeforelayout(linearlayout.java:1369) @ android.widget.linearlayout.measurevertical(linearlayout.java:660) @ android.widget.linearlayout.onmeasure(linearlayout.java:553) @ android.view.view.measure(view.java:12723) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:4704) @ android.widget.framelayout.onmeasure(framelayout.java:293) @ android.view.view.measure(view.java:12723) @ android.widget.linearlayout.measurevertical(linearlayout.java:812) @ android.widget.linearlayout.onmeasure(linearlayout.java:553) @ android.view.view.measure(view.java:12723) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:4704) @ android.widget.framelayout.onmeasure(framelayout.java:293) @ com.android.internal.policy.impl.phonewindow$decorview.onmeasure(phonewindow.java:2092) @ android.view.view.measure(view.java:12723) @ android.view.viewrootimpl.performtraversals(viewrootimpl.java:1068) @ android.view.viewrootimpl.handlemessage(viewrootimpl.java:2455) @ android.os.handler.dispatchmessage(handler.java:99) @ android.os.looper.loop(looper.java:137) @ android.app.activitythread.main(activitythread.java:4462) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:511) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:806) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:573) @ dalvik.system.nativestart.main(native method) ------------ the line code happens:
mtrackdrawable = a.getdrawable(r.styleable.switch_track); mtrackdrawable.getpadding(mtemprect); it no longer crashes because of text style missing because set them manually on app start.
here track styles in various files of compatibility project, theme being used:
v11:
<style name="appthemedark" parent="@android:style/theme"> <item name="switchstyle">@style/switch_dark</item> <item name="textappearance">@style/textappearance</item> </style> v14:
<style name="appthemedark" parent="@android:style/theme.devicedefault"> <item name="switchstyle">@style/switch_dark</item> <item name="textappearance">@style/textappearance</item> </style> common:
<style name="switch_dark"> <item name="track">@drawable/switch_track_holo_dark</item> <item name="thumb">@drawable/switch_inner_holo_dark</item> <item name="texton">@string/texton</item> <item name="textoff">@string/textoff</item> <item name="thumbtextpadding">12dip</item> <item name="switchminwidth">96dip</item> <item name="switchpadding">16dip</item> <item name="switchtextappearance">@style/textappearance</item> </style> anyone used 1 of libraries , faced such issue?
i solved this, number of "tricks" found in various posts , web sites.
originally theme defined in manifest.xml on application tag only.
1- applied same theme every activity defined in manifest.xml 2- customized transparent activity use custom theme include switch theme make sure app never start without 3- added settheme in oncreate() of java application class make sure appropriate theme set when application starts.
not sure if 3 needed, worked. user reproduce issue consistently: app started first time: fc in activity using switch, restart no fc!?
Comments
Post a Comment