【问题标题】:Android : Class not allowed to be inflated android.widget.SwitchAndroid:类不允许被夸大 android.widget.Switch
【发布时间】:2020-05-16 15:04:25
【问题描述】:
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginTop="4dp">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:text="@string/general_dts_title"
            style="@style/TextAppearance.Compat.Notification.Line2"
            android:layout_alignParentBottom="false"
            android:layout_alignBottom="@+id/imgToggle"
            android:textSize="16sp" />

        <Switch
            android:id="@+id/imgToggle"
            android:layout_width="42dp"
            android:layout_height="28dp"
            android:layout_gravity="right"
            android:layout_alignParentEnd="false"
            android:layout_alignParentRight="true"
            android:layout_marginRight="10dp" />

    </RelativeLayout>

StatusBar:原因:android.view.InflateException:com.dts.dtsxultra:layout/view_notification_sample 中的二进制 XML 文件第 338 行:不允许对类进行充气 android.widget.Switch ...

你能帮忙吗? 我尝试删除背景属性,但仍然无法正常工作。

【问题讨论】:

  • 检查您的日志或在此处发布

标签: android xml switch-statement inflate-exception


【解决方案1】:

我已经尝试了上面的代码,没有给 textview 提供样式,它工作得很好。您面临的错误可能不是因为这段代码。

【讨论】:

    【解决方案2】:

    RemoveView 只允许某些布局和小部件膨胀。 RemoteView 不支持 android.widget.Switch,因为您得到的错误是不支持的。可以看到支持的视图列表here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多