android


Error inflating ImageView / ImageButton with ColorStateList tint value


Using an ImageView / ImageButton (AppCompatImageView / AppCompatImageButton) in conjunction with a style attribute of android:tint which makes use of a ColorStateList resource works fine on >= API 21, but throws an InflateException on API < 21.
Firstly, I don't even know whether the AppCompatImageView / (Button) tinting supports ColourStateList xml resources as an android:tint value, I can't seem to find a definitive answer to this. Suggestions I can find on S/O suggest implementing a TintableImageView etc, but these answers are quite dated, and it seems from the source of the appcompat implementations this should be a feature.
To clarify this is definitely the issue. Removing the android:tint attribute or setting it to a single colour resource works.
Also to clarify, I'm aware this is achievable programmatically. I'm trying to get it backwards compatible in xml.
Minimal example
activity_foo.xml
<android.support.v7.widget.AppCompatImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_caret_up"
style="#style/IconButton.Primary"
/>
styles.xml
<style name="IconButton.Primary">
<item name="android:tint">#color/link_button_color</item>
</style>
link_button_color.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#color/btnLinkPressedTextColor"
android:state_selected="true" />
<item android:color="#color/btnLinkPressedTextColor"
android:state_pressed="true" />
<item android:color="#color/btnLinkTextColor" />
</selector>
It looks like AppCompat drawable tinting only works for action bar and "some widgets" on < API 21, but works for all drawables on API 21+.
When you set these attributes, AppCompat automatically propagates their values to the framework attributes on API 21+. This automatically colors the status bar and Overview (Recents) task entry.
On older platforms, AppCompat emulates the color theming where possible. At the moment this is limited to coloring the action bar and some widgets.
Source: https://android-developers.googleblog.com/2014/10/appcompat-v21-material-design-for-pre.html
The answer here also has more detail: http://stackoverflow.com/a/29155611/608312

Related Links

android new permission in new version
Beta testing stage for android app, clean install?
how can I stop activity wdeviceclick back button on my device
FIll Spinner from xml response in android
Photoswipe not working in Chrome or Default mobile browsers
Parsing json with android
Unable to center the text in textview
Android CheckBox in List to Right
How to extract the substring from the string?
How to show All Locations on Map
Open Twitter URL with app, instead of browser
Android Fragment Tabs using - android.support.v4.app.Fragment
Google play in app purchases with singleTask launchMode?
show text in textview by pointwise in android
Problems with RelativeLayout Android
Consequences of using paddingLeft on android 4.2+ with RTL language

Categories

HOME
url-redirection
beautifulsoup
embedded
eclipse
deep-learning
linkedin
flex
sh
error-handling
pclxl
xbee
3d-reconstruction
settings
polling
nuget-package
google-cloud-datalab
augeas
pcl-crypto
line
onedrive-api
plink
package-managers
null-pointer
asp.net-mvc-viewmodel
google-picker
xmonad
sigma.js
squashfs
ios10.2
easeljs
epsilon
corpus
cppreference
gitlab-api
paragraph
utorrent
angularjs-material
android-sugarorm
vue-chartjs
indy10
engine.io
python-pptx
flatmap
postgresql-8.4
x++
robomongo
carrot2
scalding
java-bytecode-asm
css-transforms
trigger.io
jtree
django-1.10
branch-prediction
juice-ui
simplepie
custom-lists
webjars
vulcanize
macaulay2
avspeechsynthesizer
invoke-sqlcmd
cycle2
sapi
boomerang
jdi
ons-api
video-player
doctype
rpart
haskell-warp
graphics2d
botan
mraid
code-documentation
device-tree
tweenlite
lnk
grails-plugin-rabbitmq
dot42
qscrollarea
sphinxql
ie8-compatibility-mode
cmmi
dopostback
mkv
paginator
inkcanvas
cross-database
hibernateexception
role
screen-size
fsevents
update-statement
tmx
undefined-index
updatesourcetrigger
aspmenu
echo3
purepdf
lemmatization
contentpresenter

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App