標籤:android tint drawablecompat
安卓對表徵圖著色以節省apk體積,網上有很多介紹到的,使用也很簡單
<ImageView android:tint="@android:color/white" android:backgroundTint="@android:color/black" />
平時都這樣使用,今天得在代碼中改,所以記錄一下
第一種
Drawable icon;if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP){ icon = getResources().getDrawable( R.drawable.ic_back_black );}else{ icon = getResources().getDrawable( R.drawable.ic_back_black ,getTheme());}ColorFilter filter = new LightingColorFilter( Color.WHITE, Color.WHITE);icon.setColorFilter(filter);image.setImageDrawable(icon);
第二種,需要V4包
Drawable icon1;if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP){ icon1 = getResources().getDrawable( R.drawable.ic_back_black );}else{ icon1 = getResources().getDrawable( R.drawable.ic_back_black ,getTheme());}Drawable tintIcon = DrawableCompat.wrap(icon1);DrawableCompat.setTint(tintIcon, Color.WHITE);//DrawableCompat.setTintList(tintIcon, Color.WHITE);titleBack1.setImageDrawable(tintIcon);
好吧,兩個都能實現.也不知道哪個更好.
網上有不少相關介紹
http://www.cnblogs.com/helloandroid/p/4779061.html
http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2016/0128/3923.html
本文出自 “蒼蠅學android” 部落格,請務必保留此出處http://qq445493481.blog.51cto.com/9545543/1842972
Android改變圖片背景顏色tint(著色)或 backgroundTint