EditText中的Drawable使Activity失败

时间:2017-11-02 19:54:27

标签: android android-layout android-drawable android-design-library

当我在edittext中使用可绘制图标时,我的活动崩溃了。没有drawable一切都很好。奇怪的是,这在API级别16上崩溃,但在API级别26上没有崩溃。

这是我的错误日志:

     android.view.InflateException: Binary XML file line #0: Error inflating class android.support.v7.widget.AppCompatEditText
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2463)
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2520)
                      at android.app.ActivityThread.access$600(ActivityThread.java:162)
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1366)
                      at android.os.Handler.dispatchMessage(Handler.java:99)
                      at android.os.Looper.loop(Looper.java:158)
                      at android.app.ActivityThread.main(ActivityThread.java:5751)
                      at java.lang.reflect.Method.invokeNative(Native Method)
                      at java.lang.reflect.Method.invoke(Method.java:511)
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1083)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:850)
                      at dalvik.system.NativeStart.main(Native Method)
                   Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class android.support.v7.widget.AppCompatEditText
                      at android.view.LayoutInflater.createView(LayoutInflater.java:613)
                      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/login_password.xml from drawable resource ID #0x7f070068
                      at android.content.res.Resources.loadDrawable(Resources.java:1998)
                      at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
 Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #0: invalid drawable tag vector
                      at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:881)

这是我的EditText视图。我正在使用TextInputLayout

           <android.support.design.widget.TextInputLayout
            android:id="@+id/login_inputlayout_email"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="4dp"
            android:layout_marginTop="3dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/login_login_titel">

            <android.support.v7.widget.AppCompatEditText
                android:id="@+id/login_textEmail"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:drawablePadding="10dp"
                android:focusable="true"
                android:drawableLeft="@drawable/login_password"
                android:drawableStart="@drawable/login_password"
                android:hint="Email Adresse"
                android:inputType="textAutoComplete"
                android:singleLine="true"
                android:textColor="@color/global_edittext" />
        </android.support.design.widget.TextInputLayout>

is another problem,但已过时。我尝试了解决方案和其他答案,但没有什么对我有用。

1 个答案:

答案 0 :(得分:0)

小于21的API级别不支持xml属性的background可绘制对象。我也有同样的问题。您可以使用图像。 jpg,png或其他类似格式。