How to use selector to tint ImageView?

前端 未结 6 1153
别跟我提以往
别跟我提以往 2020-11-30 00:58

I want to tint my tabhost\'s icons using XML, instead of doing it programmatically (I wasn\'t able to do that anyway)...

I found this thread on SO: Android imagevie

6条回答
  •  天涯浪人
    2020-11-30 01:42

    With current AppCompat support library, you can use app:tint on ImageView tag which will be inflated as AppCompatImageView and handle the state change properly.

    In AppCompatImageView, you can see that mImageHelper is notified of the state change:

    @Override
    protected void drawableStateChanged() {
        super.drawableStateChanged();
        if (mBackgroundTintHelper != null) {
            mBackgroundTintHelper.applySupportBackgroundTint();
        }
        if (mImageHelper != null) {
            mImageHelper.applySupportImageTint();
        }
    }
    

    Android Studio currently gives a warning on this, but you can safely suppress it.

提交回复
热议问题