【问题标题】:Drawable not working on API 19可绘制不适用于 API 19
【发布时间】:2016-09-10 22:12:22
【问题描述】:

我在 RecyclerView 中添加了一个 FastScroller 并使用了“Bubble”-Drawable。

如果我在 API 21 上测试我的应用程序,它可以工作,但如果我在 API 19 上测试它,它会崩溃:

java.lang.RuntimeException:无法启动活动 ComponentInfo{at.guger.musixs/at.guger.musixs.ui.MainActivity}:

android.view.InflateException:二进制 XML 文件第 15 行:错误 膨胀类 at.guger.fastscroll.FastScroller ... 引起:android.view.InflateException:二进制 XML 文件第 15 行: 在.guger.fastscroll.FastScroller 膨胀类时出错

...引起:java.lang.reflect.InvocationTargetException

... 原因:android.view.InflateException: Binary XML file line #6: Error inflating class at.guger.fastscroll.FastScrollBubble

... 引起:java.lang.reflect.InvocationTargetException

... 原因:android.content.res.Resources$NotFoundException:文件 res/drawable/bubble.xml 来自可绘制资源 ID #0x7f02004b

在 android.content.res.Resources.loadDrawable(Resources.java:3457)

在 android.content.res.TypedArray.getDrawable(TypedArray.java:602)

在 android.view.View.(View.java:3767)

在 android.view.ViewGroup.(ViewGroup.java:481)

在 android.widget.FrameLayout.(FrameLayout.java:101)

在 android.widget.FrameLayout.(FrameLayout.java:97)

at.guger.fastscroll.FastScrollBubble.(FastScrollBubble.java:0)

... 38

我的 Bubble-XML 文件:

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <corners
        android:topLeftRadius="@dimen/bubble_corner_radius"
        android:topRightRadius="@dimen/bubble_corner_radius"
        android:bottomLeftRadius="@dimen/bubble_corner_radius"
        android:bottomRightRadius="0dp" />

    <solid android:color="?attr/colorAccent" />

    <size
        android:height="@dimen/bubble_size"
        android:width="@dimen/bubble_size" />
</shape>

我的 FastScroll-Bubble-Layout:

<?xml version="1.0" encoding="utf-8"?>
<TextView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/fastscroll_bubble"
    android:layout_width="64dp"
    android:layout_height="64dp"
    android:background="@drawable/bubble"
    android:gravity="center"
    android:textSize="36sp"
    tools:text="A"
    tools:visibility="visible" />

我的文件夹结构:

【问题讨论】:

  • 没有我的xml文件在默认的drawable文件夹中,就像你看到的那样
  • 我认为是标签不兼容之类的...
  • 你正在使用第三方库,你应该在作者 GitHub 上打开一个问题,提供场景和一些关于如何重现问题的信息。
  • 图书馆是我自己做的;)
  • 哦,对不起!它是开源的吗?检查一些代码会更容易......

标签: java android xml android-layout


【解决方案1】:

你的问题是在你的drawable中使用?attr/

<solid android:color="?attr/colorAccent" />

这仅在 Lollipop up 中受支持。因此对于以下所有版本,您需要将颜色直接定义为颜色资源。

<solid android:color="@color/colorAccent" />

有关更多详细信息,请参阅How to reference style attributes from a drawable?

【讨论】:

  • 哦,谢谢!我害怕我必须重建整个快速滚动,但这很容易:D
猜你喜欢
  • 2016-08-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-20
  • 1970-01-01
  • 2019-12-21
相关资源
最近更新 更多