gpt4 book ai didi

android - kitkat 版本中开关小部件的空指针异常

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:30:42 32 4
gpt4 key购买 nike

我在我的应用程序中使用了开关小部件。当我在 Lollipop 上运行应用程序时,它运行良好。但是当我运行 kitkat 版本时,它会崩溃。

xml设计:

 <Switch
android:id="@+id/act_edit_device_swtch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:switchMinWidth="40sp"
android:thumb="@null"
android:track="@drawable/switchdb" />

switchdb.xml

<?xml version="1.0" encoding="UTF-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:drawable="@drawable/onswitch" android:state_checked="true"/>
<item android:drawable="@drawable/offswitch" android:state_checked="false"/>
<item android:drawable="@drawable/offswitch"></item>

</selector>

下面是我的崩溃报告:

java.lang.NullPointerException
at android.widget.Switch.jumpDrawablesToCurrentState(Switch.java:825)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5500)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5500)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5500)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5500)
at android.widget.FrameLayout.jumpDrawablesToCurrentState(FrameLayout.java:189)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5500)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5500)
at android.widget.FrameLayout.jumpDrawablesToCurrentState(FrameLayout.java:189)
at android.view.View.onAttachedToWindow(View.java:12146)
at android.view.ViewGroup.onAttachedToWindow(ViewGroup.java:3499)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onAttachedToWindow(PhoneWindow.java:2659)
at android.view.View.dispatchAttachedToWindow(View.java:12620)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2460)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1236)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1019)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5725)

最佳答案

使用 android:thumb="@android:color/transparent" 而不是 @null

关于android - kitkat 版本中开关小部件的空指针异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35007934/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com