Reputation: 13
I want my TextView to appear for 5 seconds so it will be invisible too when the text is displayed flashy. thanks for your help
<TextView
android:id="@+id/tv"
android:layout_width="50dp"
android:layout_height="45dp"
android:layout_marginStart="4dp"
android:textColor="#FE9A2E"
android:textSize="18dp"
android:text="Hello"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteY="16dp"
android:layout_marginLeft="4dp" />
Upvotes: 0
Views: 240
Reputation: 1473
You can use Android's AlphaAnimation to make a View invisible with fade out like animation after some time.
AlphaAnimation animation = new AlphaAnimation(1f, 0f);
animation.setStartOffset(5000);
animation.setDuration(1000);
animation.setFillAfter(true);
tv.startAnimation(animation);
Details about AlphaAnimation: https://developer.android.com/reference/android/view/animation/AlphaAnimation.html
Upvotes: 0
Reputation: 752
Yes it possible using Animation
put this in res/anim folder
alpha_invisible.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:fillEnabled="true" >
<alpha
android:duration="1000"
android:fromAlpha="1.0"
android:toAlpha="0.0" />
Java file:
int time = 5000; // 5 sec
Animation animInvisible = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.alpha_invisible);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
textview.startAnimation(animInvisible);
}
}, time); // animation invisible textview after 5 sec
Upvotes: 1