Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent clickable div from being highlighted in Android WebView

Tags:

I'm using a full-screen WebView in an Android app, using API level 15. There are some on/off switches that I'm making clickable with jQuery's .click function. The approach works fine, but the click handler causes the button to be highlighted in a transparent shade of blue when the element is tapped, and it's unsightly.

None of these approaches worked to prevent the element from being highlighted:

CSS Approach

div.pill {     outline: none; } 

Click Approach

$("div.pill").click(function(Event) {     // ... other code here ...     Event.stopPropagation();     Event.preventDefault();     return false; }); 

Mousedown Approach

$("div.pill").mousedown(function(Event) {     // ... other code here ...     Event.stopPropagation();     Event.preventDefault();     return false; }); 

Here is an example of the div with a blue highlight:

WebView screenshot

Does anyone know how to prevent a clickable div from being highlighted when it's clicked?

like image 884
Zach Rattner Avatar asked Nov 29 '12 07:11

Zach Rattner


People also ask

How do you override a WebView?

If you want to override certain methods, you have to create a custom WebView class which extends WebView . Also, when you are inflating the WebView , make sure you are casting it to the correct type which is CustomWebView . CustomWebView webView = (CustomWebView) findViewById(R. id.

What are the features provided by WebView?

The WebView class is an extension of Android's View class that allows you to display web pages as a part of your activity layout. It does not include any features of a fully developed web browser, such as navigation controls or an address bar. All that WebView does, by default, is show a web page.


1 Answers

Put below code in the CSS file:

-webkit-tap-highlight-color: rgba(0, 0, 0, 0);

like image 116
Dinesh Prajapati Avatar answered Oct 01 '22 02:10

Dinesh Prajapati