本文介绍了app:srcCompat不适用于ImageView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在向库项目添加矢量可绘制支持,并使用app:srcCompat引用矢量可绘制.似乎起作用的唯一视图是ImageButton,我不确定为什么.
I'm adding vector drawable support to a library project, and using app:srcCompat to reference the vector drawable. The only view that appears to work is ImageButton and I'm not sure why.
这是我的build.gradle的相关部分
Here's the relevant piece of my build.gradle
android { defaultConfig { vectorDrawables.useSupportLibrary = true } } dependencies { testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:24.0.0' compile 'com.android.support:support-vector-drawable:24.0.0' compile 'com.android.support:animated-vector-drawable:24.0.0' compile 'uk.co.chrisjenx:calligraphy:2.2.0' }这是我的布局文件:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="schemas.android/apk/res/android" xmlns:app="schemas.android/apk/res-auto" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center_horizontal" > <ImageView android:id="@+id/iconActive" style="@style/Widget.MyCompany.Button.Icon" app:srcCompat="@drawable/activities" android:layout_marginTop="16dp" android:tint="@color/white" /> </LinearLayout>如果我只是简单地将ImageView更改为ImageButton,那么它将起作用.按钮也不起作用.
If I simply change the ImageView to an ImageButton it works. Button also does not work.
推荐答案也许您可以尝试将ImageView更改为 AppCompatImageView .这样就变成了:
Maybe you could try changing ImageView to AppCompatImageView. So it becomes:
<android.support.v7.widget.AppCompatImageView android:id="@+id/iconActive" style="@style/Widget.MyCompany.Button.Icon" app:srcCompat="@drawable/activities" android:layout_marginTop="16dp" android:tint="@color/white" />更多推荐
app:srcCompat不适用于ImageView
发布评论