Cataster Cataster - 1 month ago 16
Android Question

How can I make an animated/constant glowing effect around button in android?

I am seeking to make two buttons have a thin glow around them, kinda pulsating-fading effect

glowlike effect around button example image

The buttons have a background drawable image, and i just wanna have a glowing effect around it to make it kinda resonate with the music playing

I have already searched around multiple threads, and they were either just about an imageView, or upon pressed, or a Bitmap, so not necessarily what I am seeking

Here is my Button XML:

<Button
android:id="@+id/playEasyMode_Button"
android:layout_width="145dp"
android:layout_height="40dp"
android:layout_gravity="center_horizontal"
android:background="@drawable/play_easy_button"
android:onClick="playEasyMode"
android:layout_margin="15dp"/>


Please dont try suggesting using background drawables upon pressed and whatnot, this is not what I am looking to do. I wanna set such effect either programatically or in the XML




edit: Object Animator offloat relative layout error image

Answer Source

What you can do is you can make a relative layout as a background like this-

<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="#FFC107"
        android:alpha="0.1"
        android:layout_marginBottom="30dp">


        <Button
            android:layout_width="match_parent"
            android:layout_height="40dp"


            />

    </RelativeLayout>

i have set the alpha to 0.1 initially in relative layout.

now in activity you can write the animation of fadein and fadeout-

ObjectAnimator fadeOut = ObjectAnimator.ofFloat(relativelayout, "alpha", .5f, .1f);
        fadeOut.setDuration(300);
        ObjectAnimator fadeIn = ObjectAnimator.ofFloat(relativelayout, "alpha", .1f, .5f);
        fadeIn.setDuration(300);

        mAnimationSet = new AnimatorSet();

        mAnimationSet.play(fadeIn).after(fadeOut);

        mAnimationSet.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                mAnimationSet.start();
            }
        });

        mAnimationSet.start();