Android selector with fade in / fade out duration initially invisible

前端 未结 4 1509
无人及你
无人及你 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:50

    This seems to be a bug that happens on specific Android versions. You can turn off the android:enterFadeDuration programmatically in Java code, by accessing the Selector with a StateListDrawable:

    // Disable android:enterFadeDuration/exitFadeDuration on Android 4.2 only
    if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR1) {
        StateListDrawable stateListDrawable =
                (StateListDrawable) animatedButton.getBackground();
        stateListDrawable.setEnterFadeDuration(0);
        stateListDrawable.setExitFadeDuration(0);
    }
    

提交回复
热议问题