The android toast settings are shorter than the Toast. LENGTH_SHORT settings.

Source: Internet
Author: User

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 ~

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.