-2

enter image description hereI have a text in textview which i need it to be blinking please help me with it.

I tried this 1: How to make the textview blinking.

But here the TextView is blinking. I need only the text that is,"Text1" to blink.

AskNilesh
  • 67,701
  • 16
  • 123
  • 163
shruthi
  • 45
  • 1
  • 7
  • use a thread and write the code that makes it "blink", however you imagine that. – Stultuske Feb 08 '18 at 10:37
  • can you show screenshot of what you want to achieve? – Aj 27 Feb 08 '18 at 10:40
  • what do you mean by only the `text` to blink? as far as i think its both the same – Abdul Kawee Feb 08 '18 at 10:40
  • Or you could extend TextView and override onDraw(). For a certain period don't call super.onDraw() to not draw the text and for the other periods call it. This way you can get blinking. Don't forget to invalidate the view when changing the state to make the system redraw it and call onDraw() again. – Veselin Todorov Feb 08 '18 at 10:40

1 Answers1

1

Try this you can to use setText() to make blink effect in TextView

Try below code

<TextView
    android:id="@+id/usage"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimaryDark"
    android:gravity="center"
    android:textColor="#d92804" />

Java Code;

TextView textView;

textView = (TextView) findViewById(R.id.textView);

testBlink();

    private void testBlink() {
        final Handler handler = new Handler();
        new Thread(new Runnable() {
            @Override
            public void run() {
                int timeToBlink = 1000;
                try {
                    Thread.sleep(timeToBlink);
                } catch (Exception e) {
                }
                handler.post(new Runnable() {
                    @Override
                    public void run() {

                        if (textView.getText().toString().equals("")) {
                            textView.setText("Nilesh");
                        } else {
                            textView.setText("");
                        }
                        testBlink();
                    }
                });
            }
        }).start();
    }
Ratilal Chopda
  • 4,162
  • 4
  • 18
  • 31
AskNilesh
  • 67,701
  • 16
  • 123
  • 163