gpt4 book ai didi

android - 找不到类 'android.graphics.drawable.RippleDrawable

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:41:26 31 4
gpt4 key购买 nike

Android 应用程序意外关闭并在 log-cat 中给出以下错误。

01-22 00:33:58.470 8193-8193/? E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering
01-22 00:34:00.010 1173-1173/? E/MyTag: updateClock : 12:34
01-22 00:34:00.015 1173-1173/? E/MyTag: updateClock : 12:34 AM
01-22 00:34:00.051 1173-1173/? E/MyTag: updateClock : 12:34 AM
01-22 00:34:00.080 1432-1432/? E/ActionIcon: time changed: time = 20170122T003400Asia/Calcutta(0,21,19800,0,1485025440)
01-22 00:34:00.086 8210-8210/? E/Zygote: Zygote: error closing descriptor
libcore.io.ErrnoException: close failed: EBADF (Bad file number)
at libcore.io.Posix.close(Native Method)
at libcore.io.BlockGuardOs.close(BlockGuardOs.java:75)
at com.android.internal.os.ZygoteInit.closeServerSocket(ZygoteInit.java:221)
at com.android.internal.os.ZygoteConnection.handleChildProc(ZygoteConnection.java:879)
at com.android.internal.os.ZygoteConnection.runOnce(ZygoteConnection.java:242)
at com.android.internal.os.ZygoteInit.runSelectLoop(ZygoteInit.java:713)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:649)
at dalvik.system.NativeStart.main(Native Method)

最佳答案

对我来说,问题是 color-selector 可绘制对象,我将其用于 ImageViewtint 值。崩溃发生在 API 19 上(我假设它在 API < 21 的所有设备上)。

有问题的代码

<ImageView
android:id="@+id/icon"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="center"
android:src="@drawable/ic_music_note_white_24dp"
android:tint="@color/color_bottom_navigation_item" />

color_bottom_navigation_item.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#00CCF0" android:state_selected="true" />
<item android:color="#75848C" />
</selector>

解决方案

从 XML 中删除 android:tint 属性并像这样以编程方式设置它:

ImageView icon = findViewById(R.id.icon);
ColorStateList tint = getResources().getColorStateList(R.color.color_bottom_navigation_item);

Drawable drawable = ContextCompat.getDrawable(getContext(), R.drawable.ic_music_note_white_24dp);
drawable = DrawableCompat.wrap(drawable).mutate();
DrawableCompat.setTintList(drawable, tint);
icon.setImageDrawable(drawable);

关于android - 找不到类 'android.graphics.drawable.RippleDrawable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41783333/

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