• 自定义吐司来电显示


        private final WindowManager.LayoutParams mParams = new WindowManager.LayoutParams();
    
    
    public void showToast(String incomingNumber) {
            final WindowManager.LayoutParams params = mParams;
            params.height = WindowManager.LayoutParams.WRAP_CONTENT;
            params.width = WindowManager.LayoutParams.WRAP_CONTENT;
            params.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
    //                | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE    默认能够被触摸
                    | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
            params.format = PixelFormat.TRANSLUCENT;
            //在响铃的时候显示吐司,和电话类型一致
            params.type = WindowManager.LayoutParams.TYPE_PHONE;
            params.setTitle("Toast");
            
            //指定吐司的所在位置(将吐司指定在左上角)
            params.gravity = Gravity.LEFT+Gravity.TOP;
            
            //吐司显示效果(吐司布局文件),xml-->view(吐司),将吐司挂在到windowManager窗体上
            mViewToast = View.inflate(this, R.layout.toast_view, null);
            tv_toast = (TextView) mViewToast.findViewById(R.id.tv_toast);
            
            //从sp中获取色值文字的索引,匹配图片,用作展示
            mDrawableIds = new int[]{
                    R.drawable.call_locate_white,
                    R.drawable.call_locate_orange,
                    R.drawable.call_locate_blue,
                    R.drawable.call_locate_gray,
                    R.drawable.call_locate_green};
            int toastStyleIndex = SpUtil.getInt(getApplicationContext(), ConstantValue.TOAST_STYLE, 0);
            tv_toast.setBackgroundResource(mDrawableIds[toastStyleIndex]);
            
            //在窗体上挂在一个view(权限)
            mWM.addView(mViewToast, params);
            
            
        }
    
    <!-- 在窗体上挂在view的权限 -->
        <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
  • 相关阅读:
    UVA 562 Dividing coins --01背包的变形
    HDU 2602 Bone Collector --01背包
    Topcoder SRM 618 Div2 --900
    【转】Python 列表排序
    线段树之区间最大连续和问题
    【转】Python中string的strip,lstrip,rstrip用法
    《Python核心编程》部分代码习题实践(持续更新)
    《Python核心编程》部分错误纠正(勘误表)(持续更新)
    UVA 103 Stacking Boxes --LIS
    POJ 1836 Alignment --LIS&LDS
  • 原文地址:https://www.cnblogs.com/xufengyuan/p/6350301.html
Copyright © 2020-2023  润新知