Android vector drawable app:srcCompat not showing images -
i'm using support library show vector images on android kitkat. when test app on emulater don't see of these images. made separate layout android lollipop , above , workd (i think because i'm using src
attribute instead of srccompat
here's code i'm usign support library
<linearlayout android:layout_alignparentbottom="true" android:id="@+id/lake_detail" android:background="@drawable/my_fishing_plan_footer_line" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="90dp" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <relativelayout android:layout_marginright="3dp" android:id="@+id/fire_logo" android:layout_width="20sp" android:layout_height="20sp"> <imageview android:tint="#d74313" app:srccompat="@drawable/circle_icon" android:layout_width="30sp" android:layout_height="30sp" /> <imageview android:layout_centervertical="true" android:layout_centerhorizontal="true" app:srccompat="@drawable/lauzaviete" android:layout_width="25dp" android:layout_height="25dp" /> </relativelayout>
, it's strange because see images on android studio preview window.
original answer
use android.support.v7.widget.appcompatimageview
instead of imageview
this:
<linearlayout ... xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <android.support.v7.widget.appcompatimageview android:tint="#d74313" app:srccompat="@drawable/circle_icon" android:layout_width="30sp" android:layout_height="30sp" /> <android.support.v7.widget.appcompatimageview android:layout_centervertical="true" android:layout_centerhorizontal="true" app:srccompat="@drawable/lauzaviete" android:layout_width="25dp" android:layout_height="25dp" /> </linearlayout>
see appcompatimageview
docs here , appc:srccompat
here.
also, make sure following:
setup build.gradle
android { defaultconfig { vectordrawables { usesupportlibrary = true } } }
extend activity
appcompatactivity
public final class mainactivity extends appcompatactivity { @override protected void oncreate(@nullable bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); } }
when using app:srccompat
, make sure have correct declarations in layout:
<linearlayout ... xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> ... </linearlayout>
optional(warning: please read docs): setcompatvectorfromresourcesenabled
in application
class
public class app extends application { @override public void oncreate() { super.oncreate(); // make sure use vector drawables appcompatdelegate.setcompatvectorfromresourcesenabled(true); } }
Comments
Post a Comment