android - 膨胀 XML 类时出错 - 资源不是可绘制对象(颜色或路径)

标签 android android-resources inflate-exception

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

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

这是一个简单的注册 Activity 。

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>

可绘制的编辑文本:

<?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 和最低 API 16 的模拟器中对其进行测试

如果您需要更多信息,请告诉我。 谢谢。

最佳答案

您的可绘制对象并不太复杂,它需要处于特定的 API 级别。

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

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

关于android - 膨胀 XML 类时出错 - 资源不是可绘制对象(颜色或路径),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48611171/

相关文章:

android - 按对象属性对集合进行排序

android - Android 列表中的可扩展项

android字符串资源与应用程序大小

android - İnflater 错误 Edittext while version has changed

android - android-getMenuInflater导致崩溃

java - 在 android studio 中膨胀类 com.google.android.gms.ads.AdView 时出错

android - 来自谷歌结果的带问号的钻石

android - 如何在 android 中获取 MapView API?

android - 有没有办法从 APK 文件中获取源代码?

android-studio - 从整数资源文件设置布局引力