gpt4 book ai didi

android - 使用 TextInputLayout 时出现 InflateException

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:32:47 28 4
gpt4 key购买 nike

我正在尝试使用 Material Design (https://github.com/material-components/material-components-android/blob/master/docs/components/TextInputLayout.md) 中的 TextInputEditText,但遇到运行时异常。

这是运行日志的一部分:

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.grigori.materialtextedit, PID: 12036
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.grigori.materialtextedit/com.example.grigori.materialtextedit.MainActivity}: android.view.InflateException: Binary XML file line #9: Binary XML file line #9: Error inflating class com.google.android.material.textfield.TextInputLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: android.view.InflateException: Binary XML file line #9: Binary XML file line #9: Error inflating class com.google.android.material.textfield.TextInputLayout
Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class com.google.android.material.textfield.TextInputLayout
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.material.textfield.TextInputLayout" on path: DexPathList

我用 DexPathList 剪切了这个日志,其中包含许多 apk 文件的路径,例如:

zip file "/data/app/com.example.grigori.materialtextedit-jamgTcrgG9neBKIMcqDo7Q==/base.apk"

我的 xml 文件:

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/hint_text"/>

</com.google.android.material.textfield.TextInputLayout>

我的 build.gradle 依赖项:

    dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'}

最佳答案

在我现有的项目中实现 AndroidX 时遇到了这个问题。

implementation 'com.google.android.material:material:1.0.0-beta01'

布局 XML

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/userNameWrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/TextLabel">

旧样式

<style name="TextLabel" parent="TextAppearance.AppCompat">
<item name="android:textColorHint">@color/hint_color</item>
<item name="android:textSize">@dimen/text_20sp</item>
<item name="colorControlNormal">@color/primaryGray</item>
<item name="colorControlActivated">@color/colorPrimary</item>
</style>

新风格

<style name="TextLabel" parent="Widget.MaterialComponents.TextInputLayout.FilledBox">
<item name="android:textColorHint">@color/hint_color</item>
<item name="android:textSize">@dimen/text_20sp</item>
<item name="colorControlNormal">@color/primaryGray</item>
<item name="colorControlActivated">@color/colorPrimary</item>
</style>

关于android - 使用 TextInputLayout 时出现 InflateException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51957275/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com