参考文章
autojs还没多少人用Material组件, 今天看到别人写的Android Material组件使用详解, 用autojs来试试效果
环境
手机: Mi 11 Pro
Android版本: 11
Autojs版本: 9.0.10
源码
"ui"; $debug.setMemoryLeakDetectionEnabled(true); engines.all().map((ScriptEngine) => { if (engines.myEngine().toString() !== ScriptEngine.toString()) { ScriptEngine.forceStop(); } }); importClass(android.view.ViewOutlineProvider); importClass(android.content.res.ColorStateList); importClass(com.google.android.material.shape.RelativeCornerSize); importClass(com.google.android.material.shape.AbsoluteCornerSize); importClass(com.google.android.material.shape.CornerFamily); importClass(com.google.android.material.shape.ShapeAppearanceModel); ui.layout( <vertical margin="30"> <horizontal> <com.google.android.material.imageview.ShapeableImageView android:id="@+id/image" android:layout_width="110dp" android:layout_height="110dp" android:padding="0dp" margin="20dp" app:strokeColor="#ff0000" android:src="file://./yashu.png" /> <com.google.android.material.imageview.ShapeableImageView android:id="@+id/image2" android:layout_width="110dp" android:layout_height="110dp" android:padding="0dp" margin="20dp" app:strokeColor="#ff0000" android:src="file://./yashu.png" /> </horizontal> <horizontal> <com.google.android.material.imageview.ShapeableImageView android:id="@+id/image3" android:layout_width="110dp" android:layout_height="110dp" android:padding="0dp" margin="20dp" app:strokeColor="#ff0000" android:src="file://./yashu.png" /> <com.google.android.material.imageview.ShapeableImageView android:id="@+id/image4" android:layout_width="110dp" android:layout_height="110dp" android:padding="0dp" margin="20dp" app:strokeColor="#ff0000" android:src="file://./yashu.png" /> </horizontal> <horizontal> <com.google.android.material.imageview.ShapeableImageView android:id="@+id/image5" android:layout_width="110dp" android:layout_height="110dp" android:padding="0dp" margin="20dp" app:strokeColor="#ff0000" android:src="file://./yashu.png" /> <com.google.android.material.imageview.ShapeableImageView android:id="@+id/image6" android:layout_width="110dp" android:layout_height="110dp" android:padding="0dp" margin="20dp" app:strokeColor="#ff0000" android:src="file://./yashu.png" /> </horizontal> <horizontal> <com.google.android.material.imageview.ShapeableImageView android:id="@+id/image7" android:layout_width="110dp" android:layout_height="110dp" android:padding="0dp" margin="20dp" app:strokeColor="#ff0000" android:src="file://./yashu.png" /> <com.google.android.material.imageview.ShapeableImageView android:id="@+id/image8" android:layout_width="110dp" android:layout_height="110dp" android:padding="0dp" margin="20dp" app:strokeColor="#ff0000" android:src="file://./yashu.png" /> </horizontal> </vertical> ); let imgView = ui.image; let img = $images.read("./yashu.png"); ui.post(function () { imgView = ui.image; imgView.shapeAppearanceModel = ShapeAppearanceModel.builder() .setTopLeftCornerSize(50) .setTopRightCornerSize(50) .setBottomLeftCornerSize(50) .setBottomRightCornerSize(50) .build(); imgView = ui.image2; imgView.shapeAppearanceModel = ShapeAppearanceModel.builder().setAllCorners(CornerFamily.ROUNDED, 100).build(); imgView = ui.image3; imgView.shapeAppearanceModel = ShapeAppearanceModel.builder() .setTopLeftCorner(CornerFamily.CUT, RelativeCornerSize(0.3)) .setTopRightCorner(CornerFamily.CUT, RelativeCornerSize(0.3)) .setBottomRightCorner(CornerFamily.CUT, RelativeCornerSize(0.3)) .setBottomLeftCorner(CornerFamily.CUT, RelativeCornerSize(0.3)) .build(); imgView = ui.image4; imgView.shapeAppearanceModel = ShapeAppearanceModel.builder().setAllCornerSizes(ShapeAppearanceModel.PILL).build(); imgView = ui.image5; imgView.shapeAppearanceModel = ShapeAppearanceModel.builder() .setTopLeftCorner(CornerFamily.CUT, RelativeCornerSize(0.3)) .setTopRightCorner(CornerFamily.CUT, RelativeCornerSize(0.3)) .setBottomRightCorner(CornerFamily.CUT, RelativeCornerSize(0.3)) .setBottomLeftCorner(CornerFamily.CUT, RelativeCornerSize(0.3)) .setAllCornerSizes(ShapeAppearanceModel.PILL) .build(); imgView = ui.image6; imgView.shapeAppearanceModel = ShapeAppearanceModel.builder() .setTopLeftCorner(CornerFamily.CUT, RelativeCornerSize(0.5)) .setTopRightCorner(CornerFamily.CUT, RelativeCornerSize(0.3)) .setBottomRightCorner(CornerFamily.CUT, RelativeCornerSize(0.3)) .setBottomLeftCorner(CornerFamily.CUT, RelativeCornerSize(0.3)) .build(); imgView = ui.image7; imgView.shapeAppearanceModel = ShapeAppearanceModel.builder() .setTopLeftCorner(CornerFamily.CUT, RelativeCornerSize(0.5)) .setTopRightCorner(CornerFamily.CUT, RelativeCornerSize(0.3)) .setBottomRightCorner(CornerFamily.CUT, RelativeCornerSize(0.5)) .setBottomLeftCorner(CornerFamily.CUT, RelativeCornerSize(0.3)) .build(); imgView = ui.image8; imgView.shapeAppearanceModel = ShapeAppearanceModel.builder() .setTopLeftCorner(CornerFamily.ROUNDED, RelativeCornerSize(0.5)) .setTopRightCorner(CornerFamily.CUT, RelativeCornerSize(0)) .setBottomRightCorner(CornerFamily.CUT, RelativeCornerSize(0)) .setBottomLeftCorner(CornerFamily.CUT, RelativeCornerSize(0)) .build(); }); function printObj(obj) { var arr = []; for (var k in obj) { arr.push(k); } arr.sort(); log(arr); } events.on("exit", function () { img.recycle(); });
名人名言
思路是最重要的, 其他的百度, bing, stackoverflow, github, 安卓文档, autojs文档, 最后才是群里问问
--- 牙叔教程
声明
部分内容来自网络
本教程仅用于学习, 禁止用于其他用途