【问题标题】:Error Occuring while using ON/OFF switche in android在android中使用ON/OFF开关时发生错误
【发布时间】:2012-07-12 11:12:38
【问题描述】:

我想在我的应用程序中使用开/关开关Mentioned here。但是我的布局在设计开关时出现错误,如下所示 <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>

【问题讨论】:

  • 能否附上你的xml文件的代码?
  • 它只有一个组件是switch
  • @Paru :在为 Application 设置 @android:style/Theme.Holo 主题后尝试,还可以查看此问题 code.google.com/p/android/issues/detail?id=21017
  • style="@android:style/Theme.Holo" 在布局中添加。但没用

标签: android android-layout switch-statement


【解决方案1】:

在 API 级别 14 中添加了开关小部件。 确保在 AndroidManifest.xml 中设置 android:minSdkVersion="14"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-02-08
    • 2016-11-08
    • 2012-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多