Android的CompoundButton开关jumpDrawablesToCurrentState空崩溃 [英] Android CompoundButton Switch jumpDrawablesToCurrentState null crash

查看:997
本文介绍了Android的CompoundButton开关jumpDrawablesToCurrentState空崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有成功使用切换按钮的应用程序。我转换了应用程序对果冻豆(4.1.1)的使用。 4.1.1具有切换控件,它是一个更好看的切换按钮小部件。这两个部件派生自 CompoundButton

I have an app that successfully uses ToggleButton. I am converting the app for use on JELLY BEAN (4.1.1). 4.1.1 has Switch widget which is a better-looking ToggleButton widget. Both widgets derive from CompoundButton.

Android的对比文件是在这里:

Android's comparison documentation is here:

http://developer.android.com/guide/topics/ UI /控制/ togglebutton.html

它说:

切换按钮和开关控制是CompoundButton的子类和功能相同的方式,这样就可以实现自己的行为是一样的。

The ToggleButton and Switch controls are subclasses of CompoundButton and function in the same manner, so you can implement their behavior the same way.

所以我所做的就是采取含我的活动布局文件切换按钮 S,它复制到该目录 RES /布局-V14 / 并替换切换按钮的所有实例与切换。这意味着Android的版本14及以上将使用该布局文件与切换,低于14将使用与切换按钮布局文件。 XML是在每一个比小部件名称相同,其他。

So what I've done is taken my activity layout file containing ToggleButtons, copied it to the directory res/layout-v14/ and replaced all instances of ToggleButton with Switch. This means Android versions 14 and above will use the layout file with Switch, below 14 will use the layout file with ToggleButton. The XML is identical in each, other than 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"/>

在我的.java code我使用 CompoundButton 而已。不使用切换按钮切换的。

In my .java code I'm using CompoundButton only. Not using ToggleButton or Switch at all.

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

当我运行针对&lt; 14,它的伟大工程。和之前一样。我得到的 ToggeButton 。当我在14跑,我得在Android Widget框架空崩溃。

When I run on < 14, it works great. Same as before. I get the ToggeButton. When I run on 14, I get a null crash in the Android widget framework.

我下载了Android源。从崩溃回溯,我知道确切位置崩溃的。 Switch.java:

I downloaded the Android source. From the crash backtrace, I know exactly where the crash is. Switch.java:

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

拇指是一个新的属性切换。即便如此,我不应该定义它,对吗?它不列为强制性属性。

thumb is a new property to Switch. Even so, I shouldn't have to define it, right? It's not listed as a mandatory property.

就像一个测试,早在我的-v14的布局,我设置的android:拇指到绘制。然后我打行812为空,则跟踪。我设置的android:跟踪来绘制一个和崩溃消失了。
所以,这是怎么回事?

Just as a test, back in my -v14 layout, I set android:thumb to a drawable. Then I hit null on line 812, the track. I set android:track to a drawable, and the crash is gone. So what's going on?

为什么我打空崩溃?

我需要找到默认的跟踪拇指图形内容和将它们复制到我的应用程序?

Do I need to find the default Track and Thumb drawables, and copy them in to my app?

是我想要做的事 - 使用切换按钮和开关 - ?不可能的。

Is what I'm trying to do -- using ToggleButton and Switch -- not possible?

推荐答案

请确保您的minSdkVersion是在AndroidManifest.xml中14

make sure your minSdkVersion is 14 on AndroidManifest.xml

这篇关于Android的CompoundButton开关jumpDrawablesToCurrentState空崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆