Android无障碍实现滑动功能

本文介绍了Android 7.0中新增的手势API,包括如何通过Path和GestureDescription.Builder实现滑动手势,以及如何在AccessibilityService中使用dispatchGesture方法来触发手势,并解决了XML配置中的常见问题。
该文章已生成可运行项目,

android 7.0中引入新的手势api,它在

AccessibilityService中实现
public final boolean dispatchGesture(@NonNull GestureDescription gesture,
        @Nullable GestureResultCallback callback,
        @Nullable Handler handler)

要使用它很简单,首先声明一个Path:

Path path = new Path();
path.moveTo(100, 500);    //点击(100,500)做为起点
path.lineTo(800,500);     //水平向右滑动到(800,500)

再创建一个GestureDescription,添加上面的路径,最多可以添加10个路径,实现多段滑动

GestureDescription.Builder builder = new GestureDescription.Builder();
GestureDescription description = builder.addStroke(
           new GestureDescription.StrokeDescription(path, 20L, 1000L)).build();

boolean  ret=mAccService.dispatchGesture(description,
                    new AccessibilityService.GestureResultCallback() {
             @Override
                public void onCompleted(GestureDescription gestureDescription) {
                    super.onCompleted(gestureDescription);
     
本文章已经生成可运行项目
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值