Why doesn't `android:foreground` attribute work?

后端 未结 4 908
深忆病人
深忆病人 2020-12-08 23:12

Take a look at this small android app:

MainActivity.java:

package io.github.gsaga.toucheventtest;

import android.support.v7.app.AppCompatActivity;
i         


        
4条回答
  •  無奈伤痛
    2020-12-08 23:23

    Another solution is to wrap your image with a , set it as your ImageView's background, and use tint and tintMode to "hide" the src image so the background image that has the ripple over it is visible.

    
    
    
    
    
    
    
    
    
        
    
    
    

    Not only this works on API 21+ but if your image has rounded corners – or is another type of non-rectangle shape, like a star or a heart icon – the ripple will remain in its bounds instead of filling the view's rectangle bounds, which gives a better look in some cases.

    See this Medium article for an animated GIF to see how this technique compares to using a or the foreground attribute.

提交回复
热议问题