Arun kumar
Arun kumar

Reputation: 1894

Android how to add animation to flash the setting preference so that it gets the user's attention

I am having a setting Preference screen which I am opening from another screen and auto-scrolling to a particular setting preference but I want to add blink/flash animation to the scrolled preference so that the user gets attention.

It should be like when we open the android setting screen and search setting and on opening the setting it is highlighting.

I did research on multiple places but did not find related to it.

Upvotes: 0

Views: 277

Answers (1)

Ton
Ton

Reputation: 9796

I have done that with this code.

new Thread(() -> {
    requireActivity().runOnUiThread(() -> {
        Preference myPreference = findPreference("myPreference");
        View myView = getListView().getChildAt(myPreference.getOrder());
        BlinkView(myView , 10);
    });
}).start();


public void BlinkView(View oView, int iNumberOfRepetitions) {
    if (oView == null) return;

    final Animation animation = new AlphaAnimation(1, 0); // Change alpha from fully visible to invisible
    animation.setDuration(80);
    animation.setInterpolator(new LinearInterpolator()); // do not alter animation rate
    animation.setRepeatCount(iNumberOfRepetitions);
    animation.setRepeatMode(Animation.REVERSE); // Reverse animation at the end so the button will fade back in

    oView.startAnimation(animation);
}

Upvotes: 0

Related Questions