zoukankan      html  css  js  c++  java
  • 自定义Toast

       Toast是Android中用来显示显示信息的一种机制,和Dialog不一样的是,Toast是没有焦点的,而且Toast显示的时间有限,过一定的时间就会自动消失。而且Toast主要用于向用户显示提示消息.

    #默认效果

    mbutton.setOnClickListener(new Button.OnClickListener() {
        @Override            
        public void onClick(View v) {  
              String path = mEditText.getText().toString();  
              if(path.equals("") ){               
                 Toast.makeText(MainActivity.this,"网址不能为空", Toast.LENGTH_SHORT).show();   
              }   
        }   
    });

    image

    #自定义效果

     inflater.inflate(R.layout.custom, (ViewGroup) findViewById(R.id.llToast));

     ImageView image = (ImageView) layout .findViewById(R.id.tvImageToast);//设置图片
     image.setImageResource(R.drawable.icon);   //设置标题

     TextView title = (TextView) layout.findViewById(R.id.tvTitleToast);
     title.setText("Attention");   //设置文字

     TextView text = (TextView) layout.findViewById(R.id.tvTextToast);  
     text.setText("完全自定义Toast");
     toast = new Toast(getApplicationContext());   
     toast.setGravity(Gravity.RIGHT | Gravity.TOP, 12, 40);  //设置位置
     toast.setDuration(Toast.LENGTH_LONG);
     toast.setView(layout);
     toast.show();
    复制代码

    #其他线程显示

    new Thread(new Runnable() {
    public void run() {
    showToast();
    }
    }).start();
  • 相关阅读:
    Python数据结构与算法—栈
    var_export 和 var_dump
    PHp 下标是 区分大小写的
    和眼睛相处
    css 3 animation
    background-attachment: fixed | attachment 区别
    js 函数表达和函数声明
    function 和 new Function
    lastIndexOf js
    substring substr slice js比较
  • 原文地址:https://www.cnblogs.com/neo-java/p/6831156.html
Copyright © 2011-2022 走看看