Start a Project

WebView with BottomSheeDialog

In android we use several views to show content to the user Additionally, to show the web content or load the web URL on the application we can use the intent to redirect the links to the browser but in some cases, we may need more control over the UI. In this case, a WebView is used for displaying content.

To load the WebView content in the app we must have access to the Internet. To get internet access, we need to add the request INTERNET permission in the manifest file.

In this blog, we will learn how to use the WebView inside the Bottom Sheet fragment.

How to add WebView

To add a WebView to your app, you can include the <WebView> element in your activity/Fragment layout.

To load a web page in the WebView, use can loadUrl().

For loading a basic WebView that displays a web page the above-given detail is enough. If you want more modification required then you can use the following:

Enabling fullscreen support with WebChromeClient. This class is also called when a WebView needs permission to alter the host app’s UI, such as creating or closing windows and sending JavaScript dialogs to the user.

Handling events that impact content rendering, such as progress or redirection with the help of WebViewClient. You can intercept URL loading with WebViewClient.

Change WebSettings to enable JavaScript. You can use JavaScript to access Android framework objects that you have injected into a WebView.

Bottom Sheet Dialog Fragment implementation

To load the WebView on the bottom sheet dialog fragment we have to extend the BottomSheetDialogFragment().

On Our Bottom sheet fragment, we have to override the onCreateDialog method to handle the back button press. After that, we can work on the WebView initialization on the on-view created method.

The layout will be like the one below.

The Result will be like this:

You can also check out the official documentation provided by Google click here and to learn more about the bottom sheet dialog you check the official documentation click here.

. . . . . . . . .

That’s it from my side for today, thanks for reading it until now. You can check our other android blogs Click Here.

Exit mobile version