Skip to main content

Posts

Showing posts from October, 2021

Jetpack Compose: WebView progress percentage

Introduction In the world of Android development, Jetpack Compose has quickly become a favored tool for building modern, responsive UIs. It simplifies the UI code by offering declarative syntax and allowing developers to focus more on building a seamless user experience. However, integrating features that interact with the native Android components, like WebView, can still be a bit challenging for developers who are more accustomed to the imperative approach. In this example, we will explore how to display a WebView with a progress indicator using Jetpack Compose. This tutorial walks through a simple app that displays the page load progress as a percentage when using WebView in Jetpack Compose. This example uses a combination of Jetpack Compose for UI and Android's native WebView to load and display web pages. We will break down the code to understand how the scaffold structure works in Compose, how to integrate native Android components (WebView), and how to show the loading progr...

Jetpack Compose: WebView ProgressIndicator

Introduction This Android Kotlin example demonstrates the integration of a WebView with a ProgressIndicator in a Jetpack Compose UI. Jetpack Compose, the modern toolkit for building native Android UIs, allows developers to create responsive and dynamic interfaces with less boilerplate code. Here, we see how to embed a WebView within a Compose layout and manage its loading state with a circular progress indicator, providing users visual feedback during webpage loading. In this tutorial, we will break down the components and logic used in the code, focusing on the UI elements, state management, and how the WebView client interacts with the rest of the composable elements. By the end, you'll understand how Jetpack Compose can simplify embedding traditional Android views, like WebView, into declarative UI components. Scaffold Layout The code begins by defining the main user interface inside a Scaffold composable, which serves as the base structure of the UI. The Scaffold provides a...

Jetpack Compose: How to use WebView

Introduction Jetpack Compose has become a popular framework for developing Android applications with its modern declarative approach. Despite its flexibility, there are still some scenarios where developers need to integrate traditional Android views, such as WebView , into their Compose-based UI. This can be achieved by combining the power of Jetpack Compose with Android's AndroidView interop feature, allowing developers to embed native Android views within a Compose layout. In this article, we’ll walk through how to use a WebView inside a Jetpack Compose project and provide details on how to configure it effectively. This Kotlin example demonstrates the use of WebView within a Jetpack Compose UI. We will break down the code into sections, explaining the setup, how to integrate WebView within Compose, and how to apply necessary settings for a smooth browsing experience. Let’s take a closer look at how this is done. Main Structure: Setting Up Compose Scaffold The entry point fo...

Jetpack compose: Room Add, Remove, Update

Jetpack Compose - Room Add, Remove, Update This code demonstrates a basic Android application built with Jetpack Compose that utilizes Room for data persistence. The app manages a list of "Students" with functionalities to add, remove, and update them. Key Components: Room Database: The RoomSingleton class defines a Room database with a single entity - Student . It provides methods to access the DAO (Data Access Object) for interacting with student data. Student Entity: The Student data class represents a student record with properties like ID (primary key), name (full name), and result (integer). StudentDao: This interface defines methods for CRUD (Create, Read, Update, Delete) operations on student data within the database. StudentViewModel: This ViewModel class acts as the single source of truth for student data. It holds a reference to the Room database instance and exposes functions to interact with students (insert, update, delete, clear all). Mai...