android switch button 报 java.lang.NullPointerException: Attempt to invoke virtual method 'boolean

来源:互联网 发布:梅西c罗数据对比最新 编辑:程序博客网 时间:2024/05/16 14:59

 


 在使用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上面滑动的滑块 

0 0
原创粉丝点击