zoukankan      html  css  js  c++  java
  • Android 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

    #自定义效果

    LayoutInflater inflater = getLayoutInflater();
       View layout = 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();
  • 相关阅读:
    MySQL数据库中的delete语句
    记录Jmeter集成Jenkins运行Ant做接口监听
    测试数据随机生成器(离线)
    python正则表达式
    字典、数据结构化
    python复制、浅拷贝、深拷贝
    python-list:列表-元组-字符串
    自动部署shell(结合Jenkins)
    linux问题记录
    Python操作excel
  • 原文地址:https://www.cnblogs.com/bincoding/p/5255186.html
Copyright © 2011-2022 走看看