请问autojs中如何实现画图?

安卓中是通过继承view重写私有onDraw方法中使用canvas实现的,autojs虽然可以访问安卓相关这些,但无法访问私有方法,也无法继承实现自定义,有什么可以解决的办法吗?

以下为使用onDraw(Canvas canvas)画矩形区域,及在其上画文本的实例(通过使用内部类使程序显得更加简洁,紧凑):
package com.android.test; 链接文本
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.View;
public class TestActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new TestView(this));
}
public class TestView extends View {
private Paint mPaint = new Paint();
public TestView(Context context) {
super(context);
}

@Override 
protected void onDraw(Canvas canvas) { 
  // TODO Auto-generated method stub 
  super.onDraw(canvas); 
   
  String text = "Android - 机器人";      
  mPaint.setColor(Color.WHITE); 
   
  Paint paint = new Paint(); 
  paint.setColor(Color.RED); 
   
  String familyName = "宋体"; 
  Typeface font = Typeface.create(familyName,Typeface.BOLD); 
  paint.setTypeface(font); 
   
  paint.setTextSize(22); 
   
  canvas.drawRect(new Rect(0, 0, 320, 240), mPaint); 
  canvas.drawText(text, 0, 100, paint); 
} 

}
}

ui.xx.on("draw",func)

开发者

最新内测版加入了Canvas的api,加群586823180注明论坛id获取~

  • 3
    帖子
  • 949
    浏览

与 Auto.js 的连接断开,我们正在尝试重连,请耐心等待