【问题标题】:cant use VectorDrawableCompat in dependencied library不能在依赖库中使用 VectorDrawableCompat
【发布时间】:2016-06-02 14:15:53
【问题描述】:

我正在使用一些来自 maven 的库,我已经在 gradle(Android Studio) 中有这个

dependencies {
    //...other librarys
    compile 'com.android.support:recyclerview-v7:23.3.0'
    compile 'com.android.support:appcompat-v7:23.0.1'
}

我想将它用于兼容 VectorDrawable 作为旧 sdk 上 ImageView 的源代码 和背景。 但似乎没有任何效果。

在布局xml中:

xmlns:app="http://schemas.android.com/apk/res-auto"

<ImageView
        android:id="@+id/svg_head"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:srcCompat="@drawable/header"/>

这将是一个意外的命名空间前缀应用程序错误,如果我忽略(添加工具:忽略属性),则无法成功构建。

在java代码中:

我想为兼容的背景做这个 23.2.0 set vector drawable as background in 4.X

Drawable drawable = VectorDrawableCompat.create(getResources(), R.drawable.header, getTheme());

但是类

VectorDrawableCompat

AppcompatDrawableManager

找不到类(只显示红名,没有其他提示)

我用其他库很好,这是怎么回事???

【问题讨论】:

    标签: android vector android-support-library


    【解决方案1】:

    对于 VectorDrawableCompat 和 AppCompatDrawableManager,至少需要支持库 v23.2.0

    所以改成

    compile 'com.android.support:appcompat-v7:23.2.0'
    

    请参阅this android develer 博客文章,了解如何使用 gradle 进一步设置。

    【讨论】:

    • 啊...我更新了 recyclerview 但忽略了这一点。但是 NavigationView 例外,所以我也更新了 support.design。然后我无法findviewbyid到ImageView...我应该进一步做什么?(导航视图中的ImageView作为滑动菜单,全部在mainactivity中)
    • @matsuiCao 我不知道,这听起来与您的问题不同
    • thanks : ).btw,即使你知道,navigationView.getHeaderView(0).findviewbyid(R.id.xxx) 在 navigationview(app:headerlayout="layout/header " 在 xml 中)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-10-17
    • 2013-12-02
    • 1970-01-01
    • 2016-12-11
    • 1970-01-01
    • 2016-04-03
    • 2023-03-30
    相关资源
    最近更新 更多