我想要一个在我的应用程序中提到的开/关开关。但我的布局在设计交换机时出错,如下所示<Switch
android:textOn="ON"
android:textOff="OFF"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
我得到的错误是
`ENTRY com.android.ide.eclipse.adt 4 0 2012-07-12 16:33:07.619
!MESSAGE main.xml: Failed to find style 'switchStyle' in current theme
!ENTRY com.android.ide.eclipse.adt 4 0 2012-07-12 16:33:07.620
!MESSAGE main.xml: Failed to find style 'switchStyle' in current theme
!ENTRY com.android.ide.eclipse.adt 4 0 2012-07-12 16:33:07.620
!MESSAGE main.xml: Failed to find style 'switchStyle' in current theme
!ENTRY com.android.ide.eclipse.adt 4 0 2012-07-12 16:33:07.621
!MESSAGE main.xml: Failed to find style 'switchStyle' in current theme
!ENTRY com.android.ide.eclipse.adt 4 0 2012-07-12 16:33:07.622
!MESSAGE main.xml: Failed to find style 'switchStyle' in current theme
!ENTRY com.android.ide.eclipse.adt 4 0 2012-07-12 16:33:07.622
!MESSAGE main.xml: Failed to find style 'switchStyle' in current theme
!ENTRY com.android.ide.eclipse.adt 2 0 2012-07-12 16:33:07.637
!MESSAGE main.xml: You must supply a layout_width attribute.
!ENTRY com.android.ide.eclipse.adt 2 0 2012-07-12 16:33:07.638
!MESSAGE main.xml: You must supply a layout_height attribute.
我的xml文件。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Switch
android:textOn="ON"
android:textOff="OFF"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
Switch小部件是在api级别14中添加的。确保您在AndroidManifest.xml 中设置了android:minSdkVersion="14"