在使用switch时,在Android 5.0版本时会报空指针异常
java.lang.NullPointerException:
Attempt to invoke virtual method 'boolean android.graphics.drawable.Drawable.getPadding(android.graphics.Rect)' on a null object reference
这个是Android 5.0的一个bug
需要在 <Switch
android:id="@+id/switch_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/button_START"
android:layout_alignTop="@id/button_START"
android:textOn="开启 "
android:textOff="关闭 "
android:layout_marginLeft="10dp"
android:thumb="@drawable/********" 添加自己的资源
android:track="@drawable/*******"
/>
该空间中添加红色标注部分。
thumb属性指的是:switch上面滑动的滑块