gpt4 book ai didi

android - 借助支持库 (23.4.0),无法在 Android API 19 中正确加载 Vector Drawable

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

最近想用Vector Drawable来管理所有的图标。 Vector Drawable 在 Android API 21+ 上运行良好,但当我尝试在我的一台测试设备 [Amazon KFTHWI Android 4.4.3 API 19] 上使用它时,所有图标根本无法加载!

我遵循了提示 HereHere .但是还是不行....

这是我的配置:

在项目gradle脚本文件中:

buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
classpath ...
}
}

所以我的gradle插件版本应该是2.0+

在主模块gradle脚本文件中:

android{
...
defaultConfig{
...
vectorDrawables.useSupportLibrary = true
...
}
}
dependencies{
...
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:gridlayout-v7:23.4.0'
...
}

此主模块包含应用程序。我编译 gridlayout-v7 库的原因是因为我在应用程序中使用了一些 Gridlayout。

这是我的实现:

因为我需要根据接收到的数据生成一些 View ,所以我在java代码中设置了图片源。

ImageView icon = new ImageView(this);
icon.setImageResource(R.drawable.ic_lock_black_24dp);

ic_lock_black_24dp.xml 是从 Vector Asset Studio 中的 Material Icon 库生成的。

我的期望:

我相信我在主模块 gradle 脚本文件中的配置会阻止 Android Studio 为 Vectors 生成 Png,并允许 Android 在运行时直接为 Vectors 生成 Drawable。

但我只说对了一部分……我的配置实际上阻止了 Android Studio 在构建时生成 Png。但是我的旧 android 设备 [API 19] 无法从 Vectors 生成 Drawables!!所以现在应用程序中没有图标...

以下是异常(exception)情况:[Amazon KFTHWI Android 4.4.3 API 19]

W/ImageView:Unable to find resource:2130837702
android.content.res.Resources$NotFoundException: File res/drawable/ic_lock_black_24dp.xml from drawable resource ID#0x7f0200c6
at android.content.res.Resources.loadDrawable(Resources.java:2206)
at android.content.res.Resources.getDrawable(Resources.java:707)
at android.widget.ImageView.resolveUri(ImageView.java:651)
at android.widget.ImageView.onMeasure(ImageView.java:774)
at android.view.View.measure(View.java:17038)
at android.widget.RelativeLayout.measureChild(RelativeLayout.java:689)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:473)
at android.view.View.measure(View.java:17038)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5191)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:17038)
at android.widget.RelativeLayout.measureChild(RelativeLayout.java:689)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:473)
at android.view.View.measure(View.java:17038)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5191)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1052)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:590)
at android.view.View.measure(View.java:17038)
at android.support.v7.widget.GridLayout.measureChildWithMargins2(GridLayout.java:896)
at android.support.v7.widget.GridLayout.measureChildrenWithMargins(GridLayout.java:906)
at android.support.v7.widget.GridLayout.onMeasure(GridLayout.java:945)
at android.view.View.measure(View.java:17038)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5191)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:17038)
at android.widget.ScrollView.measureChildWithMargins(ScrollView.java:1273)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.widget.ScrollView.onMeasure(ScrollView.java:373)
at android.view.View.measure(View.java:17038)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5191)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:17038)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5191)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:17038)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5191)
at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:327)
at android.view.View.measure(View.java:17038)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5191)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2346)
at android.view.View.measure(View.java:17038)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2004)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1176)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1368)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1057)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5857)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:815)
at android.view.Choreographer.doCallbacks(Choreographer.java:628)
at android.view.Choreographer.doFrame(Choreographer.java:598)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:801)
at android.os.

具有讽刺意味的是,如果我不使用 AppCompat 支持库,所有图标都会很好地显示,但我知道这是因为 Android Studio 在构建时会生成 Png。我什至可以在 APK 中找到那些 Png。

我的问题:

现在,我仍然希望在旧的 Android 设备中受益于 Vector Drawable,这意味着我仍在努力避免使用 Pngs...有人可以给我一些提示或告诉我我在哪些步骤中做错了什么吗?

最佳答案

你必须说 new AppCompatImageView(this)。手动创建 View 时,您必须添加 AppCompat 前缀。

关于android - 借助支持库 (23.4.0),无法在 Android API 19 中正确加载 Vector Drawable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37352325/

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