The android toast settings are shorter than the Toast. LENGTH_SHORT settings.
Recently, I have been engaged in android development. Many things have not considered versatility when used. For example, I often use toast and the Toast that comes with the system. LENGTH_LONG is 3.5 seconds, Toast. LENGTH_SHORT is 2 seconds. Sometimes we find Toast. LENGTH_SHORT is longer than we want. Here we can use handler to manually cancel the toast and use it as a general method. Here I will list this method for your reference:
/***** Display toast, and define the display length by yourself. * Param1: The activity passes in the context * param2: the content of the toast we need to display * param3: time length long type, the length of time we pass in (such as 500) */public static void showToast (final Activity activity, final String word, final long time) {activity. runOnUiThread (new Runnable () {public void run () {final Toast toast = Toast. makeText (activity, word, Toast. LENGTH_LONG); toast. show (); Handler handler = new Handler (); handler. postDelayed (new Runnable () {public void run () {toast. cancel () ;}}, time );}});}
I will summarize a lot later and extract a lot of code that can be shared in my project, which can reduce my workload. At the same time, you can paste all your shared code for future reference ~