zoukankan      html  css  js  c++  java
  • Toast提示信息

    用Toast来作为操作成功以及用户误操作等等的提示,非常的简单。直接上代码:

    创建方式一:

       ps: 此处没有设置toast的其他属性,均使用默认的风格(个人觉得默认的风格除了字体比较小之外 还是挺好看的)

        // 利用Toast.makeText来创建toast 也可以直接用toast类的构造器
    
                    Toast toast = Toast.makeText(this, "simple hint",
                    // 设置该Toast提示信息的持续时间
                            Toast.LENGTH_LONG);
                    toast.show();

     

    创建方式二:

        Toast toast = Toast.makeText(ToastTest.this,
                            "toast with Pic info", Toast.LENGTH_LONG);
    
                    toast.setGravity(Gravity.CENTER, 0, 0);
                    
                    // !!!获取Toast提示里原有的View
                    View toastView = toast.getView();
    
                    ImageView image = new ImageView(ToastTest.this);
                    image.setImageResource(R.drawable.tools);
    
                    // 创建一个LinearLayout容器
                    LinearLayout ll = new LinearLayout(ToastTest.this);
                    // 向LinearLayout添加图片和原有的View
                    ll.addView(image);                                
                    ll.addView(toastView);
    
                    // 通过setView自定义 toast的显示  (想怎么整这个view就怎么整 as u wish)
                    toast.setView(ll);  
                    toast.show();
    
                }
  • 相关阅读:
    什么是经验
    Linux驱动开启调试信息
    insecticide|contradictions| at large|delay doing|
    timber|stain|compensate|
    whip|resist|patch|intimate|
    chop|divorce|harsh|mutual|compel|
    crack|erosion|strip|
    stack|session|fuss|anniversary
    abrupt|promising
    nevertheless|magnificent |prosperous|
  • 原文地址:https://www.cnblogs.com/mushishi/p/3394672.html
Copyright © 2011-2022 走看看