Android CompoundButton Switch jumpDrawablesToCurrentState null crash

I have an application that uses successfully ToggleButton. I am converting an application for use in JELLY BEAN (4.1.1). 4.1.1 has a widget Switch, which is a more convenient widget ToggleButton. Both widgets come out of CompoundButton.

The documentation compared to Android is here:

http://developer.android.com/guide/topics/ui/controls/togglebutton.html

It says:

The ToggleButton and Switch elements are subclasses of CompoundButton and work the same way, so you can implement their behavior the same way.

So, I made my activity layout file containing ToggleButtons, copied it to a directory, res/layout-v14/and replaced all instances ToggleButtonwith Switch. This means that Android version 14 and above will use the layout file c Switch, below 14 will use the layout file s ToggleButton. XML is identical to everyone except the widget name.

<Switch
 android:id="@+id/settings_some_option_on_off"
 android:textOn="@string/settings_toggle_on"
 android:textOff="@string/settings_toggle_off"
 android:gravity="center"
 android:paddingRight="@dimen/size_padding_minor"
 android:layout_weight="1"
 android:layout_gravity="center"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"/>

In my .java code I use only CompoundButton. Do not use ToggleButtonor Switchat all.

private CompoundButton mViewSomeOptionOnOff;
...
mViewSomeOptionOnOff = (CompoundButton) findViewById(R.id.settings_some_option_on_off);
etc.

When I run <14, it works fine. Same as before. I get it ToggeButton. When I run 14, I get a zero error in the structure of the Android widget.

I downloaded the Android source code. From the reverse of the crash, I know exactly where the crash happened. Switch.java:

808     @Override
809     public void jumpDrawablesToCurrentState() {
810         super.jumpDrawablesToCurrentState();
811         mThumbDrawable.jumpToCurrentState();    <------ boom
812         mTrackDrawable.jumpToCurrentState();
813     }

thumb - Switch. , , ? .

, -v14, android:thumb drawable. 812, track. android:track drawable, . , ?

?

track thumb ?

, , ToggleButton Switch?

+3
2

, minSdkVersion 14 AndroidManifest.xml

+4

, api 14 - nandeesh.

0

Source: https://habr.com/ru/post/1625947/


All Articles