• Android弹出UI界面---Toast


    1.默认展示

    1     // 第一个参数:当前的上下文环境。可用getApplicationContext()或this 
    2     // 第二个参数:要显示的字符串。也可是R.string中字符串ID 
    3     // 第三个参数:显示的时间长短。Toast默认的有两个LENGTH_LONG(长)和LENGTH_SHORT(短),也可以使用毫秒如2000ms 
    4     Toast toast=Toast.makeText(getApplicationContext(), "默认的Toast", Toast.LENGTH_SHORT); 
    5     //显示toast信息 
    6     toast.show(); 

    2.自定义显示位置

    1     Toast toast=Toast.makeText(getApplicationContext(), "自定义显示位置的Toast", Toast.LENGTH_SHORT); 
    2             //第一个参数:设置toast在屏幕中显示的位置。我现在的设置是居中靠顶 
    3             //第二个参数:相对于第一个参数设置toast位置的横向X轴的偏移量,正数向右偏移,负数向左偏移 
    4             //第三个参数:同的第二个参数道理一样 
    5             //如果你设置的偏移量超过了屏幕的范围,toast将在屏幕内靠近超出的那个边界显示 
    6             toast.setGravity(Gravity.TOP|Gravity.CENTER, -50, 100);  
    7             //屏幕居中显示,X轴和Y轴偏移量都是0 
    8             //toast.setGravity(Gravity.CENTER, 0, 0);  
    9             toast.show(); 

    3.带图片的

     1     Toast toast=Toast.makeText(getApplicationContext(), "显示带图片的toast", 3000); 
     2         toast.setGravity(Gravity.CENTER, 0, 0);  
     3         //创建图片视图对象 
     4         ImageView imageView= new ImageView(getApplicationContext()); 
     5         //设置图片 
     6         imageView.setImageResource(R.drawable.ic_launcher); 
     7         //获得toast的布局 
     8         LinearLayout toastView = (LinearLayout) toast.getView(); 
     9         //设置此布局为横向的 
    10         toastView.setOrientation(LinearLayout.HORIZONTAL); 
    11         //将ImageView在加入到此布局中的第一个位置 
    12         toastView.addView(imageView, 0); 

    转载自:https://blog.csdn.net/weixin_30379973/article/details/95134675

  • 相关阅读:
    python 函数2
    数据结构----栈
    python 函数
    数据结构----队列
    python 数据类型_字典和集合
    python 数据类型_数组和元组
    python 数据类型_整数_浮点数
    数据结构----链表
    laravel5.5 自带的忘记密码邮箱找回功能小记
    laravel5.5使用sendCloud邮件服务
  • 原文地址:https://www.cnblogs.com/rainbow-1/p/14593457.html
Copyright © 2020-2023  润新知