扩充XML类时出错 - 资源不是Drawable(颜色或路径)

时间:2018-02-04 17:46:51

标签: android android-resources inflate-exception

为什么当我运行我的项目时出现此错误?我一直在寻找这个问题,但我找不到任何解决方案

 Unable to start activity ComponentInfo: android.view.InflateException:             
 Binary XML file line #0: Error inflating class <unknown>

这是一项简单的注册活动。

The error

以下是代码:

XML文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>

<include layout="@layout/layout_topbar_toolbar"
    android:id="@+id/signup_toolbar" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:padding="25dp"
    android:layout_marginTop="25dp"
    android:layout_below="@id/signup_toolbar">


    <android.support.design.widget.TextInputEditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="15dp"
        android:maxLines="1"
        android:imeOptions="actionNext"
        android:inputType="textEmailAddress"
        android:hint="@string/form_email_short"
        android:id="@+id/input_email"
        android:background="@drawable/edittext_white_square"
        android:textCursorDrawable="@null"
        android:textSize="@dimen/text_edit_text"/>

    <android.support.design.widget.TextInputEditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="2dp"
        android:padding="15dp"
        android:maxLines="1"
        android:imeOptions="actionDone"
        android:inputType="textPassword"
        android:hint="@string/form_password_short"
        android:id="@+id/input_password"
        android:background="@drawable/edittext_white_square"
        android:textCursorDrawable="@null"
        android:textSize="@dimen/text_edit_text"/>

    <android.support.v7.widget.AppCompatButton
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="15dp"
        android:text="Sign Up!"
        android:id="@+id/btn_create"
        android:padding="12dp"
        android:textSize="@dimen/text_button"
        android:textColor="@color/white"
        android:background="@drawable/button_accent_square"/>

</LinearLayout>
</RelativeLayout>

工具栏XML:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:theme="@style/Base.ThemeOverlay.AppCompat.Dark.ActionBar">
</android.support.v7.widget.Toolbar>

edittext drawable:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape>
        <solid
            android:color="@color/white"/>
        <stroke android:width="1dp"
            android:color="@color/greyXLight"/>
        <corners
            android:radius="3dp"/>
    </shape>
</item>

我正在使用API​​ 22和min API 16

在模拟器中测试它

如果您需要更多信息,请与我们联系。 感谢。

1 个答案:

答案 0 :(得分:2)

您的drawable并不复杂,需要处于特定的API级别。

将其移至res/drawable(如果不存在则创建此内容)。

或者至少制作一个v16可绘制文件夹,使其符合您设置的最低API级别