无法在Android Studio中编译项目:Gradle:无效符号:'switch'

6

我正在使用Android Studio编译该项目。项目的最小SDK版本为14,目标版本为17。

我正在使用以下代码。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".MainActivity">


        <Switch
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="New Switch"
            android:id="@+id/switch" android:layout_alignBottom="@+id/button3" android:layout_toRightOf="@+id/button3"
            android:layout_marginLeft="44dp"/>


</RelativeLayout>

enter image description here


问题是编译错误,如图所示。 - user2126670
1个回答

13

如果您将开关的ID更改为"@+id/switch"以外的其他名称,就可以解决此错误。例如:

您可以通过更改开关的ID为除了"@+id/switch"之外的其他名称来解决此错误。例如:

 <Switch
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="New Switch"
            android:id="@+id/Switch"
            android:layout_below="@+id/Switch"
            android:layout_alignLeft="@+id/Switch"/>

会是一个有效的开关。

来源:https://code.google.com/p/android/issues/detail?id=55720


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接