Android点击它时避免关闭Toast

时间:2017-08-22 17:43:51

标签: android android-toast

这是我展示Toast消息的方式。

Toast.makeText(getActivity(), "This is my Toast message!",Toast.LENGTH_LONG).show();

当我点击Toast时它会消失。 当我点击它时,我怎么能避免Toast突然消失。

4 个答案:

答案 0 :(得分:2)

Toast不会因突然点击而消失。 ,它将在持续时间u set

时消失

答案 1 :(得分:1)

我建议您使用Snackbar

Snackbar在持续时间上有var variables:URLVariables = new URLVariables(); variables.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, loaderIOErrorHandler); var varSend:URLRequest = new URLRequest("https://gteckids.000webhostapp.com/gteckids/login.php"); varSend.method = URLRequestMethod.POST; varSend.data = variables; function loaderIOErrorHandler(e:Event){ trace("Error loading image thumbnail"); } var varLoader:URLLoader = new URLLoader; varLoader.dataFormat = URLLoaderDataFormat.VARIABLES; varLoader.addEventListener(Event.COMPLETE, completeHandler) variables.Parent_Username = uname_txt.text; variables.ParentPassword = pass_txt.text; variables.sendRequest = "parse"; varLoader.load(varSend); function completeHandler(event:Event):void { var phpVar1 = event.target.data.var1; if(phpVar1!="No"){ btn_ok.visible = true ; lis.visible = true; parent_id.text = phpVar1; } else{ btn_okw.visible = true ; lis1.visible = true; } } 属性,所以我认为它几乎就是你想要的。

答案 2 :(得分:0)

Toast在交互时不会关闭,这取决于您设置的持续时间

LENGTH_SHORT和LENGTH_LONG为0和1.如果您想要更长时间的内容,请使用操作栏通知

答案 3 :(得分:0)

Andorid Toast可用于在短时间内显示信息。 Toast包含要快速显示的消息,并在一段时间后消失。

您也可以创建自定义吐司

//Creating the LayoutInflater instance  
            LayoutInflater li = getLayoutInflater();  
        //Getting the View object as defined in the customtoast.xml file  
            View layout = li.inflate(R.layout.customtoast,  
              (ViewGroup) findViewById(R.id.custom_toast_layout));  

        //Creating the Toast object   
            Toast toast = new Toast(getApplicationContext());  
            toast.setDuration(Toast.LENGTH_SHORT);  
            toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);  
            toast.setView(layout);//setting the view of custom toast layout  
            toast.show();  

OR ..

Toast toast=Toast.makeText(getApplicationContext(),"Hello Javatpoint",Toast.LENGTH_SHORT);  
toast.setMargin(50,50);  
toast.show();  

您可以将for循环用于持续时间