System Font in Android

By admin, 7 四月, 2023

How to use system font in WebView of Android?


You can use the following code to access and use the system font in a WebView of Android:

// Get the system font
Typeface typeface = ResourcesCompat.getFont(context, R.font.system_font);

// Create a String containing the HTML code with the font-family css attribute set to the system font
String htmlString = "<html><head><style>body{ font-family: '" + typeface.toString() + "'; }</style></head><body>Hello World!</body></html>";

// Set the HTML content of the WebView
webView.loadDataWithBaseURL(null, htmlString, "text/html", "utf-8", null);

How to change system font in Android?

1. On your Android device, go to Settings.

2. Tap on Display.

3. Tap on Font.

4. Select the font you would like to use.

5. Tap OK to save your changes.



Restricted HTML

  • 允许的HTML标签:<a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id> <img src>
  • 自动断行和分段。
  • 网页和电子邮件地址自动转换为链接。
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.