gpt4 book ai didi

android - 将 background drawable 设置为 TextView 导致 java.lang.StackOverflowError

转载 作者:太空狗 更新时间:2023-10-29 13:53:37 26 4
gpt4 key购买 nike

我想在 TextView 的背景中使用 png 图像添加一些波纹效果,发现 this Post

我有 action_darwer.xml 可绘制为

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="?attr/selectableItemBackgroundBorderless" android:state_pressed="true" /> <!-- pressed -->
<item android:drawable="@drawable/drawer" /> <!-- default -->
</selector>

并将其设置为 TextView 为

<TextView android:id="@+id/action_drawer"
android:layout_marginLeft="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/action_drawer"/>

它根本不工作并给出错误

java.lang.StackOverflowError: stack size 8MB
at android.content.res.ColorStateList.valueOf(ColorStateList.java:102)
at android.graphics.drawable.RippleDrawable$RippleState.<init>(RippleDrawable.java:919)
at android.graphics.drawable.RippleDrawable.createConstantState(RippleDrawable.java:914)
at android.graphics.drawable.RippleDrawable.createConstantState(RippleDrawable.java:94)
at android.graphics.drawable.LayerDrawable.<init>(LayerDrawable.java:126)
at android.graphics.drawable.LayerDrawable.<init>(LayerDrawable.java:122)
at android.graphics.drawable.RippleDrawable.<init>(RippleDrawable.java:979)
at android.graphics.drawable.RippleDrawable.<init>(RippleDrawable.java:94)
at android.graphics.drawable.RippleDrawable$RippleState.newDrawable(RippleDrawable.java:945)
at android.content.res.Resources.getCachedDrawableLocked(Resources.java:2777)
at android.content.res.Resources.getCachedDrawable(Resources.java:2745)
at android.content.res.Resources.loadDrawable(Resources.java:2586)
at android.content.res.TypedArray.getDrawable(TypedArray.java:749)
at android.graphics.drawable.StateListDrawable.inflateChildElements(StateListDrawable.java:182)
at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:127)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1133)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:1037)
at android.content.res.Resources.loadDrawableForCookie(Resources.java:2718)
at android.content.res.Resources.loadDrawable(Resources.java:2614)
at android.content.res.TypedArray.getDrawable(TypedArray.java:749)
at android.graphics.drawable.StateListDrawable.inflateChildElements(StateListDrawable.java:182)
at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:127)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1133)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:1037)
at android.content.res.Resources.loadDrawableForCookie(Resources.java:2718)
at android.content.res.Resources.loadDrawable(Resources.java:2614)
at android.content.res.TypedArray.getDrawable(TypedArray.java:749)
at android.graphics.drawable.StateListDrawable.inflateChildElements(StateListDrawable.java:182)
at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:127)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1133)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:1037)
at android.content.res.Resources.loadDrawableForCookie(Resources.java:2718)
at android.content.res.Resources.loadDrawable(Resources.java:2614)
at android.content.res.TypedArray.getDrawable(TypedArray.java:749)
at android.graphics.drawable.StateListDrawable.inflateChildElements(StateListDrawable.java:182)
at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:127)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1133)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:1037)
at android.content.res.Resources.loadDrawableForCookie(Resources.java:2718)
at android.content.res.Resources.loadDrawable(Resources.java:2614)
at android.content.res.TypedArray.getDrawable(TypedArray.java:749)
at android.graphics.drawable.StateListDrawable.inflateChildElements(StateListDrawable.java:182)
at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:127)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1133)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:1037)
at android.content.res.Resources.loadDrawableForCookie(Resources.java:2718)
at android.content.res.Resources.loadDrawable(Resources.java:2614)
at android.content.res.TypedArray.getDrawable(TypedArray.java:749)
at android.graphics.drawable.StateListDrawable.inflateChildElements(StateListDrawable.java:182)
at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:127)
at android.graphi
02-16 13:12:53.567 22641-22641/org.team.asl.carticon E/JavaBinder: !!! FAILED BINDER TRANSACTION !!!
02-16 13:12:53.568 22641-22641/org.team.asl.carticon E/AndroidRuntime: Error reporting crash
android.os.TransactionTooLargeException
at android.os.BinderProxy.transactNative(Native Method)
at android.os.BinderProxy.transact(Binder.java:504)
at android.app.ActivityManagerProxy.handleApplicationCrash(ActivityManagerNative.java:4294)
at com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException(RuntimeInit.java:89)
at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693)
at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690)

如何解决这个问题?任何建议将不胜感激。谢谢。

最佳答案

StackOverflowError occurs because an application recurses too deeply.

首先修改background

<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true"
android:drawable="@drawable/pressed/> // Press State
<item android:state_focused="true"
android:drawable="@drawable/focused"/> // Focused
<item android:drawable="@drawable/drawer"/> // Default State

</selector>

有关详细信息,请查看 How can I modify ripple color when using ?

关于android - 将 background drawable 设置为 TextView 导致 java.lang.StackOverflowError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42268441/

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