Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make the textview blinking

Guys i have a textview which i need it to be blinking please help me with it.

<TextView         android:id="@+id/usage"        android:layout_marginTop="220dip"        android:layout_marginLeft="45dip"        android:layout_marginRight="15dip"        android:typeface="serif"                    android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="Google "        android:textColor="#030900"/> 

I want the google text to be blinking

like image 317
Goofy Avatar asked Feb 15 '12 13:02

Goofy


People also ask

How do you animate TextView?

To start the animation we need to call the startAnimation() function on the UI element as shown in the snippet below: sampleTextView. startAnimation(animation); Here we perform the animation on a textview component by passing the type of Animation as the parameter.

How do you strikethrough text in TextView?

If you want to show a strike-through text you can do it programming using PaintFlags. You can set paint flags Paint. STRIKE_THRU_TEXT_FLAG to a TextView and it will add a strike-through to the text. TextView textView = (TextView) findViewById(R.

Can I make a TextView clickable?

Just like Buttons and ImageViews we can add onClickListeners to TextViews by simply adding the attribute android:onClick="myMethod" to your TextView XML tag. The other way, TextView tv = (TextView) this.

Does blink HTML?

The <blink> HTML element is a non-standard element which causes the enclosed text to flash slowly. Warning: Do not use this element as it is obsolete and is bad design practice.


Video Answer


2 Answers

You can use this:

TextView myText = (TextView) findViewById(R.id.myText );  Animation anim = new AlphaAnimation(0.0f, 1.0f); anim.setDuration(50); //You can manage the blinking time with this parameter anim.setStartOffset(20); anim.setRepeatMode(Animation.REVERSE); anim.setRepeatCount(Animation.INFINITE); myText.startAnimation(anim); 

It's the same answer I gave in this post Blinking Text in android view

Hope this helps!

like image 62
SolArabehety Avatar answered Sep 18 '22 06:09

SolArabehety


Use XML Animations for this purpose :

R.anim.blink

<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android">     <alpha android:fromAlpha="0.0"         android:toAlpha="1.0"         android:interpolator="@android:anim/accelerate_interpolator"         android:duration="600"         android:repeatMode="reverse"         android:repeatCount="infinite"/> </set> 

Blink Activity: use it like this :-

public class BlinkActivity extends Activity implements AnimationListener {      TextView txtMessage;     Button btnStart;      // Animation     Animation animBlink;      @Override     protected void onCreate(Bundle savedInstanceState) {         // TODO Auto-generated method stub         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_blink);          txtMessage = (TextView) findViewById(R.id.txtMessage);         btnStart = (Button) findViewById(R.id.btnStart);          // load the animation         animBlink = AnimationUtils.loadAnimation(this,                 R.anim.blink);          // set animation listener         animBlink.setAnimationListener(this);          // button click event         btnStart.setOnClickListener(new View.OnClickListener() {              @Override             public void onClick(View v) {                 txtMessage.setVisibility(View.VISIBLE);                  // start the animation                 txtMessage.startAnimation(animBlink);             }         });      }      @Override     public void onAnimationEnd(Animation animation) {         // Take any action after completing the animation          // check for blink animation         if (animation == animBlink) {         }      }      @Override     public void onAnimationRepeat(Animation animation) {      }      @Override     public void onAnimationStart(Animation animation) {      }  } 

Let me know if you have any queries..

like image 22
Gaurav Arora Avatar answered Sep 17 '22 06:09

Gaurav Arora