在使用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


需要在          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上面滑动的滑块 

更多相关文章

  1. Android 关于WebView的相关属性
  2. RecylcerView中的子view matchParent属性失效的问题
  3. 【Android】Android中 Paint 字体、粗细等属性的一些设置
  4. 安卓笔记:安卓控件属性大全
  5. android中实现指针滑动的动态效果
  6. android layout属性 .

随机推荐

  1. Android(安卓)volley框架加载网络图片
  2. android:程序中安装APK方法
  3. android 如何从sqlite读取数据到spinner
  4. Android(安卓)Http 异步请求
  5. Android(安卓)LayoutInflater用法
  6. android 处理图片工具
  7. Android日志服务 记录日志
  8. Android(安卓)常见问题收集 (持续更新)
  9. How to install android studio on linux
  10. Android中Bitmap、Drawable、byte[]转换