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:
Does anyone know how to prevent a clickable div from being highlighted when it's clicked?
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.
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.
Put below code in the CSS file:
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With