文章90
标签1
分类38

部分代码笔记

1,悬浮绘制

    function 绘制矩形(x,y,x1,y1){
    var window = floaty.rawWindow(<canvas id = "board"   h = "{{device.height}}"
    w = "{{device.width}}"/> );//设置绘制的最大范围为设备分辨率
    window.setTouchable(false);//让悬浮窗不接收点击事件,就是穿透
    setInterval(() => {}, 3000)
    paint = new Paint()
    paint.setStrokeWidth(10);
    paint.setColor(colors.RED);//设置颜色
    paint.setStyle(Paint.Style.STROKE);
    window.board.on("draw", function (canvas) {
    canvas.drawRect(x,y-getStatusBarHeight() ,x1,y1-getStatusBarHeight(),paint)
    
    });
}

2, 获取状态栏高度

function getStatusBarHeight() {

let resources = context.getResources();

let resourceId = resources.getIdentifier("status_bar_height", "dimen", "android");

let height = resources.getDimensionPixelSize(resourceId);

return height;

}

3,自定义函数另外一个方法

var funcname=function(参数){console.log(参数)}
funname(参数)//使用
funcname(参数).toString()//将代码全部转为字符串

4,替换字符串最后一个字符为任意字符

string.replace(/.$/, '替换内容'); //(/.$/为最后一个字符

4,删除数组元素

var c=["1","2","30","2","2"]
//c.splice(1,3)代表删除数组c中索引1-3的数,即:["2","30","2"],剩余:c=["1","2"]
var afterc=c.splice(1,3)
//这里的afterc就是数组c中索引1-3的数
console.log(c);//c=["1","2"]
console.log(afterc);//["2","30","2"]
// 删除指定位置元素(如删除第3个元素30)
c.splice(2,2)
// ["1","2","2","2"]
 

    0 评论

    评论已关闭

    ">