Android:Toast提示框

简介:

Toast提示框:

1
2
3
4
5
6
7
8
9
10
findViewById(R.id.button1).setOnClickListener( new  OnClickListener()
         {
                                    
             @Override
             public  void  onClick(View v)
             {
                 //Toast.makeText(context对象, text提示内容, duration时间长短),记得加show()方法
                 Toast.makeText(MainActivity. this , "下载完成" , Toast.LENGTH_SHORT).show();
             }
         });



自定义Toast方法:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
private  void  clickToast()
    {
        Toast toast =  new  Toast( this );
        // 设置View
        LayoutInflater inflater = getLayoutInflater();
        View layout = inflater.inflate(R.layout.toast_layout,  null ); //通过布局
        toast.setView(layout);
        //设置显示位置和显示时间
        toast.setGravity(Gravity.CENTER,  60 0 );
        toast.setDuration(Toast.LENGTH_SHORT);
        toast.show();
          
    }
      
    private  void  clickToast1()
    {
        Toast toast =  new  Toast( this );
        // 设置View
        TextView textView =  new  TextView( this );
        textView.setBackgroundColor(Color.BLUE);
        textView.setText( "定制toast" );
        toast.setView(textView);
        //设置显示位置和显示时间
        toast.setGravity(Gravity.CENTER,  60 0 );
        toast.setDuration(Toast.LENGTH_SHORT);
        toast.show();
          
    }





本文转自 glblong 51CTO博客,原文链接:http://blog.51cto.com/glblong/1198603,如需转载请自行联系原作者
目录
相关文章
|
6月前
|
Android开发
android之Toast使用
android之Toast使用
51 0
|
11月前
|
编解码 Android开发
Android自定义ProgressBar,实现漂亮的进度提示框
Android自定义ProgressBar,实现漂亮的进度提示框
|
12月前
|
XML 监控 Java
Android消息提示框及CheckBox组件
Android消息提示框及CheckBox组件
105 0
|
12月前
|
Android开发 数据安全/隐私保护 开发者
ApeForms | C#WinForm弹出简易的消息提示框 (仿Android Toast消息提示)
在使用手机的时候经常会见到屏幕的中下方会弹出消息提示框,它就是Toast。 ApeForms中也实现了非常简洁易用Toast,与Android的Toast不同的是,ApeForms允许开发者设置不同的弹出模式。此外还针对PC端有鼠标的情况进行了改进,当鼠标悬停于消息弹出框之上时弹出框不会消失。
306 0
ApeForms | C#WinForm弹出简易的消息提示框 (仿Android Toast消息提示)
|
Android开发
Android 快别用Toast了,来试试Snackbar
🔥 应用场景 🔥 源码 💥 Toast.setGravity() 💥 Toast.isSystemRenderedTextToast() 🔥 Toast 提供的方法 💥 Toast.setView() 源码 🔥 Snackbar 💥 代码实现 💥 效果 💥 工具类
925 0
Android 快别用Toast了,来试试Snackbar
|
Android开发
android中的提示信息显示方法(toast应用)
android中的提示信息显示方法(toast应用)
233 1
|
API Android开发
干货|APP自动化Android特殊控件Toast识别
干货|APP自动化Android特殊控件Toast识别
|
Android开发
从Toast显示原理初窥Android窗口管理
从Toast显示原理初窥Android窗口管理
182 0
从Toast显示原理初窥Android窗口管理
|
Android开发
Android之Toast的高级使用
Android之Toast的高级使用
201 0
|
XML Android开发 数据格式
安卓 topic-通知 Toast
http://developer.android.youdaxue.com/guide/topics/ui/notifiers/toasts.html#Positioning 创建自定义Toast View To create a custom layout, define a View layout, in XML or in your application code, and pass the root View object to the setView(View) method. For example, you can create the layout for the toast
119 0