Last active
March 26, 2023 11:57
-
-
Save lisawray/78c33f76809d2bcbbec9983e2c141a70 to your computer and use it in GitHub Desktop.
Revisions
-
Lisa Wray revised this gist
Apr 8, 2016 . 2 changed files with 25 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -16,12 +16,23 @@ protected void onCreate(Bundle savedInstanceState) { DataBindingUtil.setContentView(this, R.layout.activity_main); } /** * Unlike the support library app:srcCompat, this will ONLY work with vectors. * @param imageView * @param resourceId */ @BindingAdapter("android:src") public static void setImage(ImageView imageView, int resourceId) { Drawable drawable = VectorDrawableCompat.create(imageView.getResources(), resourceId, imageView.getContext().getTheme()); imageView.setImageDrawable(drawable); } /** * Unlike the support library app:srcCompat, this will ONLY work with vectors. * @param textView * @param resourceId */ @BindingAdapter("android:drawableLeft") public static void setDrawableLeft(TextView textView, int resourceId) { Drawable drawable = VectorDrawableCompat.create(textView.getResources(), resourceId, textView.getContext().getTheme()); Drawable[] drawables = textView.getCompoundDrawables(); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,9 @@ <import type="com.xwray.vectorbinding.R"/> </data> <LinearLayout android:orientation="vertical" android:gravity="center_horizontal" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.xwray.vectorbinding.MainActivity"> @@ -17,8 +19,17 @@ android:layout_height="wrap_content" android:layout_gravity="center" tools:drawableLeft="@drawable/ic_star" android:drawableLeft="@{R.drawable.ic_star}" android:text="Hello World!"/> <ImageView android:src="@{R.drawable.ic_star}" tools:src="@drawable/ic_star" android:tint="@color/colorAccent" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LinearLayout> </FrameLayout> </layout> -
Lisa Wray created this gist
Apr 8, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ package com.xwray.vectorbinding; import android.databinding.BindingAdapter; import android.databinding.DataBindingUtil; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.support.graphics.drawable.VectorDrawableCompat; import android.support.v7.app.AppCompatActivity; import android.widget.TextView; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); DataBindingUtil.setContentView(this, R.layout.activity_main); } /** * Unlike the support library app:srcCompat, this will ONLY work with vectors. * @param textView * @param resourceId */ @BindingAdapter("app:drawableLeftCompat") public static void setDrawableLeft(TextView textView, int resourceId) { Drawable drawable = VectorDrawableCompat.create(textView.getResources(), resourceId, textView.getContext().getTheme()); Drawable[] drawables = textView.getCompoundDrawables(); textView.setCompoundDrawablesWithIntrinsicBounds(drawable, drawables[1], drawables[2], drawables[3]); } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ <?xml version="1.0" encoding="utf-8"?> <layout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto"> <data> <import type="com.xwray.vectorbinding.R"/> </data> <FrameLayout android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.xwray.vectorbinding.MainActivity"> <TextView android:gravity="center_vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" tools:drawableLeft="@drawable/ic_star" app:drawableLeftCompat="@{R.drawable.ic_star}" android:text="Hello World!"/> </FrameLayout> </layout> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ apply plugin: 'com.android.application' android { compileSdkVersion 23 buildToolsVersion "23.0.2" defaultConfig { applicationId "com.xwray.vectorbinding" minSdkVersion 14 targetSdkVersion 23 versionCode 1 versionName "1.0" vectorDrawables.useSupportLibrary = true } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } dataBinding { enabled = true } } dependencies { compile 'com.android.support:appcompat-v7:23.3.0' }