Android: WebView onClick not work?

南楼画角 提交于 2020-01-14 04:46:09

问题


I going to hide and show the Layout onclick of the webview.

I have code like below:

@Override
public void onClick(View v) {
    switch(v.getId()){
    case R.id.backButton:
        finish();
        break;
    case R.id.webView:
        if(bottomShow){
            bottomLayout.setVisibility(View.GONE);
            bottomShow = false;
        }
        else{
            bottomLayout.setVisibility(View.VISIBLE);
            bottomShow = true;
        }

        break;
    }
}

I have also set the clickListener as like

webView.setOnClickListener(this);

but even after doing that i am not getting any effect.

Why i am not able to get action on click on the webview ??

After Somehelp i have try it onTouchListener like below:

@Override
public boolean onTouch(View v, MotionEvent event) {
    switch(v.getId()){
        case R.id.webView:
            if(event.getAction() == MotionEvent.ACTION_UP){
                //Toast.makeText(getApplicationContext(), "Hello", Toast.LENGTH_SHORT).show();
                if(bottomShow){
                    bottomLayout.setVisibility(View.GONE);
                    bottomShow = false;
                }
                else{
                    bottomLayout.setVisibility(View.VISIBLE);
                    bottomShow = true;
                }
                return true;
            }

            break;
    }
    return false;
}

Now it works but webView is not smoothly scrolling as it does before.

So whats the proper solution for that ? or whats wrong in my code if it is ??

Please help me.

Thanks.


回答1:


Try with OnTouchListener of Webview



来源:https://stackoverflow.com/questions/9129018/android-webview-onclick-not-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!