带有api 16和Webview(Android)的MotionEvent
我想制作一个MotionEvent来控制WebView。如果api低于16,则一切都可以使用:带有api 16和Webview(Android)的MotionEvent,android,webview,motionevent,Android,Webview,Motionevent,我想制作一个MotionEvent来控制WebView。如果api低于16,则一切都可以使用: long downTime = SystemClock.uptimeMillis(); long eventTime = SystemClock.uptimeMillis() + 500; float x = 50f; float y = 50f; // List of meta states found here: developer.android.com/ref
long downTime = SystemClock.uptimeMillis();
long eventTime = SystemClock.uptimeMillis() + 500;
float x = 50f;
float y = 50f;
// List of meta states found here: developer.android.com/reference/android/view/KeyEvent.html#getMetaState()
int metaState = 0;
MotionEvent me = MotionEvent.obtain(
downTime,
eventTime,
action,
x,
y,
metaState
);
view.dispatchTouchEvent(me);
但是如果api更高,那么我得到一个错误:Source不是Source\u CLASS\u PIONTER。然后我将代码更改为:
long downTime = SystemClock.uptimeMillis();
long eventTime = SystemClock.uptimeMillis() + 500;
float x = 50f;
float y = 50f;
// List of meta states found here: developer.android.com/reference/android/view/KeyEvent.html#getMetaState()
int metaState = 0;
MotionEvent.PointerCoords p[] = null;
MotionEvent.PointerProperties p2[] = null;
p[0] = new MotionEvent.PointerCoords();
p[0].x = x;
p[0].y = y;
p2[0] = new MotionEvent.PointerProperties();
p2[0].toolType = MotionEvent.TOOL_TYPE_FINGER;
p2[0].id = 0;
MotionEvent me = MotionEvent.obtain(downTime, eventTime, action, 1, p2, p, metaState, 0, 1f, 1f, 0,0, 0, 0);
view.dispatchTouchEvent(me);
但它没有起作用。你有什么可以帮我的吗?
对不起,我的英语不好
来自德国的问候
MotionEvent me = MotionEvent.obtain(
downTime,
eventTime,
action,
x,
y,
metaState
);
me.setSource(4098);
view.dispatchTouchEvent(me);
对我有用