zoukankan      html  css  js  c++  java
  • Android原生控件 -- Toast(弹出组件)

    ⒈用途

    • Toast是一个消息提示组件
    • 可以设置显示的位置(自己有默认位置)
    • 自定义显示内容(例如:添加一个图片)
    • 简单封装

    ⒉使用

      默认

    Toast.makeText(getApplicationContext(),"",Toast.LENGTH_LONG).show();

      居中弹出

            Toast toastCenter = Toast.makeText(getApplicationContext(),"",Toast.LENGTH_LONG);
            toastCenter.setGravity(Gravity.CENTER,0,0);
            toastCenter.show();

      带图片的消息弹出

            Toast toastCustom = new Toast(getApplicationContext());
            LayoutInflater inflater = LayoutInflater.from(getApplicationContext());
            View view = inflater.inflate(R.layout.layout_toast,null);
            ImageView imageView = view.findViewById(R.id.iv_toast);
            TextView textView = view.findViewById(R.id.tv_toast);
            imageView.setImageResource(R.drawable.icon_smile);
            textView.setText("自定义Toast");
            toastCustom.setView(view);
            toastCustom.setDuration(Toast.LENGTH_LONG);
            toastCustom.show();

      简单封装

    public class ToastUtil {
        public static Toast mToast;
        public static void showMsg(Context context,String msg){
            if(mToast == null){
                mToast = Toast.makeText(context,msg,Toast.LENGTH_LONG);
            }else{
                mToast.setText(msg);
            }
            mToast.show();
        }
    }

      

  • 相关阅读:
    Qt之根据扩展名获取文件图标、类型
    C++根据扩展名获取文件图标、类型
    Qt之QFileIconProvider(根据扩展名获取文件图标、类型)
    Qt之QTemporaryFile
    Qt之QFileIconProvider
    Qt之字典划词
    Qt之滚动字幕
    Qt之QThread
    Python 安装 httplib2
    Qt之QTimer
  • 原文地址:https://www.cnblogs.com/fanqisoft/p/12160251.html
Copyright © 2011-2022 走看看