How to show a view for 3 seconds, and then hide it?

后端 未结 4 639
北恋
北恋 2020-12-23 22:23

I tried with threads, but android throws \"CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.\".

So how can

4条回答
  •  借酒劲吻你
    2020-12-23 22:55

    There is an easier way to do it: use View.postDelayed(runnable, delay)

    View view = yourView;
    view.postDelayed(new Runnable() {
            public void run() {
                view.setVisibility(View.GONE);
            }
        }, 3000);
    

    It's not very precise: may be hidden in 3.5 or 3.2 seconds, because it posts into the ui thread's message queue.

    Use post() or runOnUiThread() just something as setTimeout().

提交回复
热议问题