Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Change Font Face of WebView in Android Using Kotlin



This example demonstrates how to change the font face of Webview in Android using Kotlin.

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.

Example




Step 3 − Create an assets folder. Right click asset folder >> Create a new file (webView.html) and the following code −


WebView9



   
      All our dreams can come true, if we have the courage to pursue them.” – Walt Disney.
   

Step 4 − Add the following code to src/MainActivity.kt

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.webkit.WebView
class MainActivity : AppCompatActivity() {
   override fun onCreate(savedInstanceState: Bundle?) {
      super.onCreate(savedInstanceState)
      setContentView(R.layout.activity_main)
      title = "KotlinApp"
      val webView: WebView = findViewById(R.id.webView);
      webView.loadUrl("file:///android_asset/webView.html");
   }
}

Step 5 − Add the following code to androidManifest.xml



   
      
         
            
            
         
      
   

Let's try to run your application. I assume you have connected your actual Android Mobile device with your computer. To run the app from android studio, open one of your project's activity files and click the Run icon from the toolbar. Select your mobile device as an option and then check your mobile device which will display your default screen

Updated on: 2020-07-21T07:55:30+05:30

769 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements