Android selector with fade in / fade out duration initially invisible

前端 未结 4 1506
无人及你
无人及你 2021-02-08 01:18

I\'m trying to achieve that an icon in ActionBar will not change states discretely, but by fading animation. When I add android:enterFadeDuration and android:

4条回答
  •  孤城傲影
    2021-02-08 01:53

    I had a similar problem, with my code looking like this:

    
        
        
    
    

    At first, I found a hint to get rid of enterFadeDuration and only use exitFadeDuration. That solved the problem with initial invisibility, but the view still faded into invisibility during the first interraction.

    Then, I modified my structure as follows:

    
        
        
            
                
            
        
    
    

    Basically, I just pushed the default drawable out of the selector. It's a workaround and it also works for selectors with multiple states, but has some notable limitations:

    • The default drawable is always visible as a bottom layer. It works for opaque colors, but transparency may cause undesirable results.
    • If the view starts in one of the states tested by selector, in still displays as default, because the selector still starts as invisible.

    It might not be applicable to the original problem, but it's something to consider for overcoming this behaviour of selectors.

提交回复
热议问题