How can I show a toast for a specific duration?

前端 未结 12 2145
自闭症患者
自闭症患者 2020-12-08 01:08

This is the way I have to show the Toast for 500 milliseconds. Though, it\'s showing more than a second.

Toast.makeText(LiveChat.this, \"Typing\         


        
12条回答
  •  温柔的废话
    2020-12-08 01:53

    I tried different method and this method works for me

     final Toast mytoast = Toast.makeText(getApplicationContext(), jsonObject.getString("response_message"), Toast.LENGTH_SHORT);
     mytoast.show();
    
                            Handler handler = new Handler();
                            handler.postDelayed(new Runnable() {
                                @Override
                                public void run() {
                                    mytoast.cancel();
                                }
                            }, 5000);// 5 sec
    

提交回复
热议问题