使用 ShapeableImageView 时获得"Failed to inflate ColorStateList, leaving it to the framework"



我可以使用ShapeableImageView来显示角图像,但当我检查日志时,出现了错误,但不知道是关于什么以及如何修复它。当我将view更改为ImageView时,此错误不再显示,但我无法使用角图像功能(shapeAppearanceOverlay(

这是错误日志:

W/ResourcesCompat: Failed to inflate ColorStateList, leaving it to the framework
java.lang.UnsupportedOperationException: Failed to resolve attribute at index 0: TypedValue{t=0x2/d=0x7f0300fc a=-1}
at android.content.res.TypedArray.getColor(TypedArray.java:556)
at androidx.core.content.res.ColorStateListInflaterCompat.inflate(ColorStateListInflaterCompat.java:160)
at androidx.core.content.res.ColorStateListInflaterCompat.createFromXmlInner(ColorStateListInflaterCompat.java:125)
at androidx.core.content.res.ColorStateListInflaterCompat.createFromXml(ColorStateListInflaterCompat.java:104)
at androidx.core.content.res.ResourcesCompat.inflateColorStateList(ResourcesCompat.java:229)
at androidx.core.content.res.ResourcesCompat.getColorStateList(ResourcesCompat.java:203)
at androidx.core.content.ContextCompat.getColorStateList(ContextCompat.java:519)
at androidx.appcompat.content.res.AppCompatResources.getColorStateList(AppCompatResources.java:48)
at d.b.a.e.v.c.a(MaterialResources.java:60)
at com.google.android.material.imageview.ShapeableImageView.<init>(ShapeableImageView.java:112)
at com.google.android.material.imageview.ShapeableImageView.<init>(ShapeableImageView.java:92)
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at android.view.LayoutInflater.createView(LayoutInflater.java:852)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1004)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:959)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1121)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1124)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1124)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1124)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
at android.view.LayoutInflater.inflate(LayoutInflater.java:680)
at android.view.LayoutInflater.inflate(LayoutInflater.java:532)
at f.a.a.b.d.b.d(ActivityInstallerTrackerBinding.java:164)
at f.a.a.b.d.b.c(ActivityInstallerTrackerBinding.java:158)
at mypackage.MyActivity.onCreate(MyActivity.kt:64)
at android.app.Activity.performCreate(Activity.java:8006)
at android.app.Activity.performCreate(Activity.java:7990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1329)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3584)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3775)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2246)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:233)
at android.app.ActivityThread.main(ActivityThread.java:8010)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:631)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:978)

这是我在第64行的代码

private lateinit var binding: MyActivityBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = MyActivityBinding.inflate(layoutInflater) << Line 64
setContentView(binding.root)
initView()
}

我试图将app:errorTextAppearance添加到ShapeableImageView中,因为我看到了针对这个确切错误的解决方案,但针对TextInputLayout,但仍然存在该错误。

编辑:包括ShapeableImageView xml&样式

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin8"
android:background="@drawable/corner_bg"
android:gravity="center"
android:orientation="horizontal"
android:visibility="gone"
app:layout_constraintEnd_toStartOf="@+id/glRight"
app:layout_constraintStart_toEndOf="@+id/glLeft"
app:layout_constraintTop_toBottomOf="@+id/tvUpload"
tools:visibility="visible">
<com.google.android.material.imageview.ShapeableImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:shapeAppearanceOverlay="@style/roundedImageView"
android:scaleType="fitXY"
android:adjustViewBounds="true"
android:padding="1dp"
android:alpha="0.5"
android:maxHeight="100dp"
android:minHeight="100dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="@dimen/margin16"
android:layout_weight="1"
android:drawablePadding="@dimen/margin8"
android:fontFamily="@font/din_condensed_bold"
android:gravity="center"
android:text="@string/select_successful"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/ivRemove"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/ivRemove"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/margin16"
android:src="@drawable/ic_close2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

这就是的风格

<style name="roundedImageView" parent="">
<item name="cornerFamily">rounded</item>
<item name="cornerSize">10dp</item>
</style>

将以下内容添加到ShapeableImageView:

app:strokeColor="@null"

这为我停止了logcat输出。库中似乎有问题。

相关内容

  • 没有找到相关文章

最新更新