gpt4 book ai didi

java - Android 中 webview 上的 OnClick?

转载 作者:行者123 更新时间:2023-12-02 05:04:11 25 4
gpt4 key购买 nike

我想像这样在 webView 上获取 Onclick 事件:

    webView.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub

}
});

最佳答案

    public class MyActivity extends Activity implements OnTouchListener{

private float mDownPosX;
private float mDownPosY;
private float mUpPosX;
private float mUpPosY;

private WebView webView;

private float MOVE_THRESHOLD_DP;

public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.webview_layout);

MOVE_THRESHOLD_DP = 20.0F * act.getResources().getDisplayMetrics().density;
webView v = (WebView) findViewById(R.id.webView);
v.setOnTouchListener(this);
}

@Override
public boolean onTouch(View v, MotionEvent event) {

switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
this.mDownPosX = event.getX();
this.mDownPosY = event.getY();
break;
case MotionEvent.ACTION_UP:
this.mUpPosX = event.getX();
this.mUpPosY = event.getY();
if ((Math.abs(mUpPosX - this.mDownPosX) < MOVE_THRESHOLD_DP) && (Math.abs(mUpPosY - this.mDownPosY) < MOVE_THRESHOLD_DP)) {
//your click code here
}

break;
}
return false;
}
}

关于java - Android 中 webview 上的 OnClick?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27946022/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com