TextInputLayout 在 Android Lollipop 及更高版本中崩溃
TextInputLayout Crashing in Android Lollipop and Above
我在我的一个应用程序布局中使用了 TextInputLayout。我的应用程序在 Lollipop(5.1) 及更高版本的用户设备上崩溃。
下面是错误
android.view.InflateException: Binary XML file line #34: Binary XML file line #2: Error inflating class android.support.design.widget.TextInputLayout arrow_drop_down
Caused by android.view.InflateException: Binary XML file line #34: Binary XML file line #2: Error inflating class android.support.design.widget.TextInputLayout arrow_drop_down
Caused by android.view.InflateException: Binary XML file line #2: Error inflating class android.support.design.widget.TextInputLayout arrow_drop_down
Caused by java.lang.reflect.InvocationTargetException: arrow_drop_down
Caused by android.content.res.Resources$NotFoundException: File res/drawable-v21/design_password_eye.xml from drawable resource ID #0x7f0200b1 arrow_drop_down
Caused by android.content.res.Resources$NotFoundException: File res/drawable-v21/avd_show_password.xml from drawable resource ID #0x7f02005c arrow_drop_down
Caused by android.content.res.Resources$NotFoundException: File res/drawable-v21/avd_show_password_1.xml from drawable resource ID #0x7f0201bd arrow_drop_down
Caused by org.xmlpull.v1.XmlPullParserException: Binary XML file line #1: invalid drawable tag x
我已经尝试了 Whosebug 上的所有解决方案,但它们都不起作用。 这包括使用 android:theme="@style/Theme.AppCompat"
更新我的库,但我的应用程序仍然崩溃。
TextInputLayout
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.TextInputLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:theme="@style/Theme.AppCompat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/edittext_bg"
android:id="@+id/passwordInput"
app:hintTextAppearance="@style/UI.Text.HintText"
app:errorTextAppearance="@style/UI.Text.ErrorText"
android:textColorHint="@color/inputLabelColor"
app:passwordToggleEnabled="true"
app:passwordToggleTint="#000000">
<EditText
android:textSize="18sp"
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:textColorHint="@color/inputLabelColor"
android:textColor="@android:color/black"
android:hint="@string/password_hint"
android:inputType="textPassword"
android:background="@drawable/apptheme_edit_text_holo_light"
/>
</android.support.design.widget.TextInputLayout>
build.gradle
android {
compileSdkVersion 25
buildToolsVersion '25.0.2'
defaultConfig {
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
testOptions {
unitTests.all {
testLogging {
exceptionFormat = 'full'
}
}
}
productFlavors {
}
}
dependencies {
compile 'com.android.support:design:25.1.0'
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.google.android.gms:play-services-auth:9.6.1'
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha6'
}
请帮助我摆脱这个错误。我想哭。 :(
更新
这个文件可以在生成的文件夹中找到。例如 design_password_eye.xml
可以在 /app/build/intermediates/exploded-aar/com.android.support/design/25.1.0/res/drawable-v21/design_password_eye.xml
找到
我不知道为什么它被声明为丢失并使我的应用程序崩溃
更新 2
清单(应用程序)
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.r.p">
<uses-sdk tools:overrideLibrary="com.base.ui.auth" />
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
<uses-permission android:name="android.permission.CAMERA" />
<!-- To access Google+ APIs: -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but you must specify either coarse or fine
location permissions for the 'MyLocation' functionality.
-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- EXTERNAL_STORAGE permissions are optional for Android 6.0 onwards. -->
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="22" />
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="22" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission
android:name="com.example.gcm.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.gcm.permission.C2D_MESSAGE" />
<application
android:name=".activities.AppApplication"
android:allowBackup="true"
android:hardwareAccelerated="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:largeHeap="true"
android:screenOrientation="portrait"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:replace="android:theme">
// Activities here
</application>
</manifest>
模块授权清单(com.base.ui.auth)
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.base.ui.auth">
<application>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
//activities here
</application>
</manifest>
样式
应用模块
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/md_blue_900</item>
<item name="colorAccent">@color/dialog_color</item>
<!--
This overrides the default dark or light dialog background color.
Note that if you use a dark color here, you should set md_dark_theme to
true so text and selectors look visible
-->
<item name="md_background_color">@android:color/transparent</item>
<!--To change the background of options menu-->
<item name="android:itemBackground">@color/app_actionBar</item>
<!--To change the text styling of options menu items</item>-->
<item name="android:itemTextAppearance">@style/itemStyle</item>
<item name="android:listPopupWindowStyle">@style/MyListPopupWindowStyle</item>
<item name="android:actionModeBackground">@color/app_actionBar</item>
<item name="android:actionModeCloseDrawable">@drawable/ic_action_close</item>
</style>
<style name="Toolbar" parent="Base.ThemeOverlay.AppCompat.ActionBar">
<item name="android:textColorPrimary">@color/md_white_1000</item>
<!--<item name="android:background">@color/dark_blue</item>-->
</style>
<style name="Toolbar_Popup" parent="Base.ThemeOverlay.AppCompat.ActionBar">
<item name="android:textColorPrimary">@color/md_black_1000</item>
<item name="android:background">@color/md_white_1000</item>
</style>
<style name="MyListPopupWindowStyle" parent="@android:style/Widget.Holo.Light.ListPopupWindow">
<item name="android:popupBackground">@color/app_actionBar</item>
<item name="android:textColor">@color/md_black_1000</item>
</style>
<style name="AppTheme.NoActionBar.PR" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">@color/md_white_1000</item>
<item name="colorAccent">@color/md_blue_900</item>
</style>
<style name="AppTheme.NoActionBar.PC" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">@color/md_white_1000</item>
<item name="colorAccent">@color/md_blue_900</item>
</style>
<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="windowActionModeOverlay">true</item>
<item name="android:actionModeBackground">@color/app_actionBar</item>
<item name="itemTextAppearance">@style/MyActionBar.MenuTextStyle</item>
</style
>
值-21
<resources>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:itemTextAppearance">@style/MyActionBar.MenuTextStyle</item>
<!--To change the background of options menu-->
<item name="android:itemBackground">@color/md_white_1000</item>
</style>
</resources>
模块 auth 的样式
<style name="SplashTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowBackground">@color/app_background</item>
<item name="colorPrimary">@color/authui_colorPrimary</item>
<item name="colorPrimaryDark">@color/authui_colorPrimaryDark</item>
<item name="colorAccent">@color/authui_colorAccent</item>
<item name="colorButtonNormal">@color/authui_colorPrimary</item>
<item name="android:buttonStyle">@style/UI.Button</item>
<item name="android:editTextStyle">@style/UI.EditText</item>
</style>
<style name="UI.EditText">
<item name="android:textSize">16sp</item>
<item name="android:lineSpacingExtra">8sp</item>
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:fontFamily">sans-serif</item>
<item name="android:colorActivatedHighlight">@color/authui_colorPrimary</item>
<item name="android:colorFocusedHighlight">@color/authui_colorPrimary</item>
</style>
如果您使用 Android Studio 2.3:
,请将您的 Gradle 插件更新到 2.3.0
classpath 'com.android.tools.build:gradle:2.3.0'
如果您使用的是 Android Studio 2.2 更新到 2.2.3
classpath 'com.android.tools.build:gradle:2.2.3'
此外,将您的库引用更新为 25.2.0
https://developer.android.com/studio/releases/gradle-plugin.html
似乎 TextInputLayout 仅在使用默认密码切换 Drawable 时尝试查找 design_password_eye.xml
等资源。
所以,我们可以通过设置app:passwordToggleDrawable="@null"
来避免Resources$NotFoundException
<android.support.design.widget.TextInputLayout
android:id="@+id/text_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:passwordToggleDrawable="@null"
app:errorEnabled="true">
我在我的一个应用程序布局中使用了 TextInputLayout。我的应用程序在 Lollipop(5.1) 及更高版本的用户设备上崩溃。 下面是错误
android.view.InflateException: Binary XML file line #34: Binary XML file line #2: Error inflating class android.support.design.widget.TextInputLayout arrow_drop_down
Caused by android.view.InflateException: Binary XML file line #34: Binary XML file line #2: Error inflating class android.support.design.widget.TextInputLayout arrow_drop_down
Caused by android.view.InflateException: Binary XML file line #2: Error inflating class android.support.design.widget.TextInputLayout arrow_drop_down
Caused by java.lang.reflect.InvocationTargetException: arrow_drop_down
Caused by android.content.res.Resources$NotFoundException: File res/drawable-v21/design_password_eye.xml from drawable resource ID #0x7f0200b1 arrow_drop_down
Caused by android.content.res.Resources$NotFoundException: File res/drawable-v21/avd_show_password.xml from drawable resource ID #0x7f02005c arrow_drop_down
Caused by android.content.res.Resources$NotFoundException: File res/drawable-v21/avd_show_password_1.xml from drawable resource ID #0x7f0201bd arrow_drop_down
Caused by org.xmlpull.v1.XmlPullParserException: Binary XML file line #1: invalid drawable tag x
我已经尝试了 Whosebug 上的所有解决方案,但它们都不起作用。 这包括使用 android:theme="@style/Theme.AppCompat"
更新我的库,但我的应用程序仍然崩溃。
TextInputLayout
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.TextInputLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:theme="@style/Theme.AppCompat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/edittext_bg"
android:id="@+id/passwordInput"
app:hintTextAppearance="@style/UI.Text.HintText"
app:errorTextAppearance="@style/UI.Text.ErrorText"
android:textColorHint="@color/inputLabelColor"
app:passwordToggleEnabled="true"
app:passwordToggleTint="#000000">
<EditText
android:textSize="18sp"
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:textColorHint="@color/inputLabelColor"
android:textColor="@android:color/black"
android:hint="@string/password_hint"
android:inputType="textPassword"
android:background="@drawable/apptheme_edit_text_holo_light"
/>
</android.support.design.widget.TextInputLayout>
build.gradle
android {
compileSdkVersion 25
buildToolsVersion '25.0.2'
defaultConfig {
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
testOptions {
unitTests.all {
testLogging {
exceptionFormat = 'full'
}
}
}
productFlavors {
}
}
dependencies {
compile 'com.android.support:design:25.1.0'
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.google.android.gms:play-services-auth:9.6.1'
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha6'
}
请帮助我摆脱这个错误。我想哭。 :(
更新
这个文件可以在生成的文件夹中找到。例如 design_password_eye.xml
可以在 /app/build/intermediates/exploded-aar/com.android.support/design/25.1.0/res/drawable-v21/design_password_eye.xml
我不知道为什么它被声明为丢失并使我的应用程序崩溃
更新 2
清单(应用程序)
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.r.p">
<uses-sdk tools:overrideLibrary="com.base.ui.auth" />
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
<uses-permission android:name="android.permission.CAMERA" />
<!-- To access Google+ APIs: -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but you must specify either coarse or fine
location permissions for the 'MyLocation' functionality.
-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- EXTERNAL_STORAGE permissions are optional for Android 6.0 onwards. -->
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="22" />
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="22" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission
android:name="com.example.gcm.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.gcm.permission.C2D_MESSAGE" />
<application
android:name=".activities.AppApplication"
android:allowBackup="true"
android:hardwareAccelerated="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:largeHeap="true"
android:screenOrientation="portrait"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:replace="android:theme">
// Activities here
</application>
</manifest>
模块授权清单(com.base.ui.auth)
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.base.ui.auth">
<application>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
//activities here
</application>
</manifest>
样式
应用模块
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/md_blue_900</item>
<item name="colorAccent">@color/dialog_color</item>
<!--
This overrides the default dark or light dialog background color.
Note that if you use a dark color here, you should set md_dark_theme to
true so text and selectors look visible
-->
<item name="md_background_color">@android:color/transparent</item>
<!--To change the background of options menu-->
<item name="android:itemBackground">@color/app_actionBar</item>
<!--To change the text styling of options menu items</item>-->
<item name="android:itemTextAppearance">@style/itemStyle</item>
<item name="android:listPopupWindowStyle">@style/MyListPopupWindowStyle</item>
<item name="android:actionModeBackground">@color/app_actionBar</item>
<item name="android:actionModeCloseDrawable">@drawable/ic_action_close</item>
</style>
<style name="Toolbar" parent="Base.ThemeOverlay.AppCompat.ActionBar">
<item name="android:textColorPrimary">@color/md_white_1000</item>
<!--<item name="android:background">@color/dark_blue</item>-->
</style>
<style name="Toolbar_Popup" parent="Base.ThemeOverlay.AppCompat.ActionBar">
<item name="android:textColorPrimary">@color/md_black_1000</item>
<item name="android:background">@color/md_white_1000</item>
</style>
<style name="MyListPopupWindowStyle" parent="@android:style/Widget.Holo.Light.ListPopupWindow">
<item name="android:popupBackground">@color/app_actionBar</item>
<item name="android:textColor">@color/md_black_1000</item>
</style>
<style name="AppTheme.NoActionBar.PR" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">@color/md_white_1000</item>
<item name="colorAccent">@color/md_blue_900</item>
</style>
<style name="AppTheme.NoActionBar.PC" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">@color/md_white_1000</item>
<item name="colorAccent">@color/md_blue_900</item>
</style>
<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="windowActionModeOverlay">true</item>
<item name="android:actionModeBackground">@color/app_actionBar</item>
<item name="itemTextAppearance">@style/MyActionBar.MenuTextStyle</item>
</style
>
值-21
<resources>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:itemTextAppearance">@style/MyActionBar.MenuTextStyle</item>
<!--To change the background of options menu-->
<item name="android:itemBackground">@color/md_white_1000</item>
</style>
</resources>
模块 auth 的样式
<style name="SplashTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowBackground">@color/app_background</item>
<item name="colorPrimary">@color/authui_colorPrimary</item>
<item name="colorPrimaryDark">@color/authui_colorPrimaryDark</item>
<item name="colorAccent">@color/authui_colorAccent</item>
<item name="colorButtonNormal">@color/authui_colorPrimary</item>
<item name="android:buttonStyle">@style/UI.Button</item>
<item name="android:editTextStyle">@style/UI.EditText</item>
</style>
<style name="UI.EditText">
<item name="android:textSize">16sp</item>
<item name="android:lineSpacingExtra">8sp</item>
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:fontFamily">sans-serif</item>
<item name="android:colorActivatedHighlight">@color/authui_colorPrimary</item>
<item name="android:colorFocusedHighlight">@color/authui_colorPrimary</item>
</style>
如果您使用 Android Studio 2.3:
,请将您的 Gradle 插件更新到 2.3.0classpath 'com.android.tools.build:gradle:2.3.0'
如果您使用的是 Android Studio 2.2 更新到 2.2.3
classpath 'com.android.tools.build:gradle:2.2.3'
此外,将您的库引用更新为 25.2.0
https://developer.android.com/studio/releases/gradle-plugin.html
似乎 TextInputLayout 仅在使用默认密码切换 Drawable 时尝试查找 design_password_eye.xml
等资源。
所以,我们可以通过设置app:passwordToggleDrawable="@null"
Resources$NotFoundException
<android.support.design.widget.TextInputLayout
android:id="@+id/text_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:passwordToggleDrawable="@null"
app:errorEnabled="true">