Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embed a custom View inside a WebView

I have a custom View that I would like to "embed" in an WebView.

By embed I mean:

  • The custom view intercepts onTouch events on its area
  • The custom view looks like a piece of the web page, so it scrolls with the surrounding text

I wrote the custom View, so I can edit it as needed

like image 464
miniBill Avatar asked May 01 '12 08:05

miniBill


People also ask

What is Webviewclient in Android?

If you want to deliver a web application (or just a web page) as a part of a client application, you can do it using 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.

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.

How do I enable JavaScript on WebView?

This example demonstrate about How to enable webview java script in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.

How can I make WebView keep a video or audio playing in the background?

Solution. After searching a lot, I found this thread. I did something similar: Just extend WebView and override onWindowVisibilityChanged . This way, the audio continues to play if the screen is locked or another app is opened.


1 Answers

Take a RelativeLayout or FrameLayout as Parent. then Put WebView as First Child Layout and then your CustomView as second child view.

After this put some code to show and hide the CustomView on some specific Action.

It will surly help you.

Enjoy. :)

like image 176
Shreyash Mahajan Avatar answered Sep 28 '22 07:09

Shreyash Mahajan