我阅读了有关SwitchCompat
在 Android 5.0 中实现 Switch 小部件的新功能。我尝试使用相同的方法,但我看不到可绘制的拇指图像,如下图所示。
我的 XML 代码如下,
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp">
<android.support.v7.widget.SwitchCompat
android:id="@+id/sampleSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:showText="false"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="20dp"
android:text="@string/action" />
<TextView
android:id="@+id/switchStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/sampleSwitch"
android:layout_marginTop="22dp"
android:text="@string/status"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
对于上述布局,我能够在预览设计(eclipse 中的图形布局选项卡)中看到拇指图像,但是当我运行我的代码时,我看不到图像。
预览设计
这是我得到的例外
java.lang.NullPointerException:尝试
boolean android.graphics.drawable.Drawable.getPadding(android.graphics.Rect)
在空对象引用上调用虚拟方法“”
请问有人可以帮忙解决问题吗?