如何显示几秒钟,一个TextView,然后使其不可见? [英] how to display a textview for few seconds and then make it invisible?

查看:341
本文介绍了如何显示几秒钟,一个TextView,然后使其不可见?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个网站是最好的,它帮助了我很多......我创建的Andr​​oid applecation初学者。
这是我第一次在这里我问一个问题..我的问题是如何显示一个TextView仅仅5秒,让它消失。当我搜索我发现了一些codeS,但我不知道如何使用它或也许我用它在错误的方式..所以任何人都可以给我一个非常简单的例子,如何做到这一点,请?
我真的会AP preciate你的帮助...... >>(我不想文本消失,我希望孔的TextView消失)

this website is the best, its help me a lot ...I am a beginner in creating android applecation . this is my first time I ask a question here.. my question is how to display a textview just for 5 seconds and the make it disappear.. when I search I found some codes but I didnt know how to use it or maybe I use it in wrong way.. so can anyone give me a very simple example how to do it please?? I really will appreciate your help......>>(I dont want the text to disappear, I want the hole textview to disappear)

推荐答案

的一种方法是使用的 CountDownTimer 如果你希望计时器显示

One way would be to use a CountDownTimer if you want the timer to show

public void onCreate(...){
...
timer = new MyCountDown(5000, 1000);
}

private class MyCountDown extends CountDownTimer
{
    long duration, interval;
    public MyCountDown(long millisInFuture, long countDownInterval) {
        super(millisInFuture, countDownInterval);
        // TODO Auto-generated constructor stub
        start();
    }

    @Override
    public void onFinish() {
        textView1.setVisibility(View.INVISIBLE);    
    }

    @Override
    public void onTick(long duration) { 
             // could set text for a timer here     
    }   
}

您也可以使用的TimerTask

下面是一个SO回答 TimerTask的一个很好的例子

另外还有各种其他方式。您可以通过文档搜索左右最适合您的需求决定。

There are also various other ways. You can search through the Docs or SO to decide which best suits your needs

的TimerTask 例如修改

Edit with TimerTask example

  Timer t = new Timer(false);
  t.schedule(new TimerTask() {
  @Override
  public void run() {
       runOnUiThread(new Runnable() {
            public void run() {
                txt.setVisibility(View.INVISIBLE);
            }
        });
    }
}, 5000);

这篇关于如何显示几秒钟,一个TextView,然后使其不可见?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆