今天在开发时,遇到一个程序的Bug,记录一下
在Dialog中展示一个布局,布局中包含了TextView报了下面的错误,最开始还以为是颜色设置的问题,反复核对了一下颜色设置并没有问题。
后来发现是主题设置有问题:
Dialog设置的主题是:
Activity设置的主题是:
将其统一起来或者直接将Dialog主题使用默认即可,并不在报下面的错误了
Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 6: TypedValue{t=0x2/d=0x7f0400cd a=7 r=0x7f06006e}
at android.content.res.TypedArray.getColorStateList(TypedArray.java:598)
at android.widget.TextView.readTextAppearance(TextView.java:3975)
at android.widget.TextView.<init>(TextView.java:1027)
at android.widget.TextView.<init>(TextView.java:968)
at androidx.appcompat.widget.AppCompatTextView.<init>(AppCompatTextView.java:100)
at androidx.appcompat.widget.AppCompatTextView.<init>(AppCompatTextView.java:95)
at androidx.appcompat.widget.DialogTitle.<init>(DialogTitle.java:46)
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at android.view.LayoutInflater.createView(LayoutInflater.java:858)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1010)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:965)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1127)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1130)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:1267)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1123)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088)
at android.view.LayoutInflater.inflate(LayoutInflater.java:686)
at android.view.LayoutInflater.inflate(LayoutInflater.java:538)
at android.view.LayoutInflater.inflate(LayoutInflater.java:481)
....
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)