How can I show a toast for a specific duration?

前端 未结 12 2185
自闭症患者
自闭症患者 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 have created a class ToastMessage in droid side.

       public class ToastMessage: IToast
            {
                public void LongAlert(string message)
                {
                    Toast toast = Toast.MakeText(Android.App.Application.Context, message, ToastLength.Short);
                    toast.Show();
                    Device.StartTimer(TimeSpan.FromSeconds(0.5), () =>
                    {               
                       toast.Cancel();
                        return false;
                    });
                }
            }
    

    I have created interface IToast

     public  interface IToast
        {
            void LongAlert(string message);
        }
    

    Calling By Dependency Service

     DependencyService.Get().LongAlert("Right Answer");
    

提交回复
热议问题