请,我需要一些帮助,我的应用程序崩溃当我打开我声明app的活动时:在TextInputLayout的xml文件中的errorEnabled = true我使用的不仅仅是教程,但没有像User input errors那样的工作
的xml:
<android.support.design.widget.TextInputLayout
android:id="@+id/tilEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/TextLabel"
app:errorTextAppearance="@style/MyErrorText"
app:errorEnabled="true"
app:hintTextAppearance="@style/TextAppearence.TextInputLayout.Red">
<EditText
android:id="@+id/edtEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/email"
android:textSize="@dimen/text_size"
android:textColor="@color/white"
android:padding="10dp"
android:inputType="textEmailAddress"
android:singleLine="true"/>
</android.support.design.widget.TextInputLayout>
式:
<style name="MyErrorText" parent="TextAppearance.AppCompat.Small">
<item name="android:textColor">#f00</item>
</style>
的活动:
tilEmail = (TextInputLayout) findViewById(R.id.tilEmail);
tilEmail.setError(null);
if (TextUtils.isEmpty(email)) {
tilEmail.setError("Email name is required"); // show error
}
错误堆栈:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.newsolution.jiibli, PID: 14042
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.newsolution.jiibli/com.newsolution.jiibli.Activity.Login}: android.view.InflateException: Binary XML file line #34: Error inflating class android.support.design.widget.TextInputLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2695)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2769)
at android.app.ActivityThread.access$900(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1430)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5910)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1405)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200)
Caused by: android.view.InflateException: Binary XML file line #34: Error inflating class android.support.design.widget.TextInputLayout
at android.view.LayoutInflater.createView(LayoutInflater.java:633)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:436)
at android.app.Activity.setContentView(Activity.java:2245)
at com.newsolution.jiibli.Activity.Login.onCreate(Login.java:65)
at android.app.Activity.performCreate(Activity.java:6178)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2648)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2769)
at android.app.ActivityThread.access$900(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1430)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5910)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1405)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:607)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:436)
at android.app.Activity.setContentView(Activity.java:2245)
at com.newsolution.jiibli.Activity.Login.onCreate(Login.java:65)
at android.app.Activity.performCreate(Activity.java:6178)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2648)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2769)
at android.app.ActivityThread.access$900(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1430)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5910)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1405)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200)
Caused by: java.lang.RuntimeException: Failed to resolve attribute at index 24
at android.content.res.TypedArray.getColor(TypedArray.java:402)
at android.widget.TextView.<init>(TextView.java:763)
at android.widget.TextView.<init>(TextView.java:685)
at android.widget.TextView.<init>(TextView.java:681)
at android.widget.TextView.<init>(TextView.java:677)
at android.support.design.widget.TextInputLayout.setErrorEnabled(TextInputLayout.java:297)
at android.support.design.widget.TextInputLayout.<init>(TextInputLayout.java:119)
at android.support.design.widget.TextInputLayout.<init>(TextInputLayout.java:82)
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:607)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:436)
at android.app.Activity.setContentView(Activity.java:2245)
at com.newsolution.jiibli.Activity.Login.onCreate(Login.java:65)
at android.app.Activity.performCreate(Activity.java:6178)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2648)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2769)
at android.app.ActivityThread.access$900(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1430)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5910)
的gradle:
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.xxxx.xx"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
repositories {
jcenter()
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
flatDir {
dirs 'libs'
}}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile(name: 'osmbonuspack_v5.3', ext: 'aar')
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
compile 'com.satsuware.lib:usefulviews:2.3.6'
compile 'com.github.ganfra:material-spinner:1.1.1'
compile 'org.osmdroid:osmdroid-android:4.3'
compile 'org.slf4j:slf4j-android:1.6.1-RC1'
compile 'com.android.support:support-v4:23.4.0'
compile 'com.mcxiaoke.volley:library-aar:1.0.0'
compile 'com.google.android.gms:play-services-gcm:8.4.0'
compile 'com.github.johnpersano:supertoasts:1.3.4@aar'
}
答案 0 :(得分:2)
在代码中显示您正在使用TextInputLayout的一些自定义主题,即@ style / TextLabel。只需确保TextLabel主题的父级是 Theme.Design 或类似Theme.Design.Light的内容
答案 1 :(得分:1)
从2019年12月开始,Google希望您使用com.google.android.material.textfield.TextInputLayout
,如果要将自己的主题设置为TextInputLayout,请确保按以下方式设置自定义样式:
<style name="CustomTheme" parent="Widget.MaterialComponents.TextInputLayout.FilledBox">
<item name="...">...</item>
</style>
请注意,FilledBox是TextInputLayout的默认主题。根据您的需求可以选择多个主题,差异记录在这里:https://material.io/develop/android/components/text-input-layout/
如果您仍在使用android.support.design.widget.TextInputLayout
,则希望该方法可以正常工作:
<style name="CustomTheme" parent="Widget.Design.TextInputLayout">
<item name="...">...</item>
</style>
答案 2 :(得分:0)
由于android:theme="@style/TextLabel"
而出现问题
只需将其从代码中删除即可解决
感谢所有