Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9028425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T06:58:52+00:00 2026-06-16T06:58:52+00:00

Trying to get the same look for TextView and WebView content, I’ve met a

  • 0

Trying to get the same look for TextView and WebView content, I’ve met a strong resistance of Android 4.

As Display getWidth() is deprecated, I’ve tried hardcoded values for Android 4 but the result is the same: at webView the text becomes larger and the scrolling appears while the textView font size is decreased.

Such a behavior for the same display type does not make any sense for me, could anyone please let me know if that is documented anywhere ?


Solution:
As pt seemed to be ignored by WebView, I had to use px scaled as much closer to sp as I can:

((TextView)findViewById(R.id.textView1)).setTextSize(TypedValue.COMPLEX_UNIT_SP,24);

font-size: " + pixelsToSp(this, 24.0f) + "px;

private float scaledPX(Context context, Float px) {
    return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, px, getResources().getDisplayMetrics());
}

Android 2.3 WVGA

Android 2.3

Android 4.1 WVGA

Android 4.1

Layout

<TextView
    android:id="@+id/textView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:text="same text"/>

<WebView
    android:id="@+id/webView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

Code

((WebView)findViewById(R.id.webView1)).getSettings().setLoadWithOverviewMode(true);
((WebView)findViewById(R.id.webView1)).getSettings().setUseWideViewPort(true);
((WebView)findViewById(R.id.webView1)).getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN); // this line was missed when the screenshots was made, it makes the images being scaled correctly

((TextView)findViewById(R.id.textView1)).setTextSize(TypedValue.COMPLEX_UNIT_PX,24);
final String width = Integer.toString(getWindowManager().getDefaultDisplay().getWidth());
final String html = "<html style = 'margin: 0px; padding: 0px;'>"
        + "<head>"
        + "<meta name='viewport' content='width=device-width; user-scalable=no; initial-scale=1.0; minimum-scale=1.0; maximum-scale=1.0; target-densityDpi=device-dpi;'/>"
        + "</head>"
        + "<body style = '"
        + "width: "
        + width
        + "px;"
        + ";'>"
        + "<div style='overflow: hidden; width: 100%; font-size: " + 24 + "px;'>"
        + "same text size"
        + "<img style='max-width: " + width + "px;' src=\"http://upload.wikimedia.org/wikipedia/commons/c/ca/Niobe050905-Siamese_Cat.jpeg\"/>"
        + "</div>"
        + "</body>";

((WebView)findViewById(R.id.webView1)).loadDataWithBaseURL("", html, "text/html", "UTF-8", "");
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T06:58:53+00:00Added an answer on June 16, 2026 at 6:58 am

    What devices are you testing on? I suspect that it has more to do with the scaling based on screen rather than the version of android itself.

    The setTextSize(float size) method uses the scaled pixels unit (sp). The html is using the pt unit which I don’t think will take into consideration the display resolution like sp will.

    Try like this:

    ((TextView)findViewById(R.id.textView1)).setTextSize(TypedValue.COMPLEX_UNIT_PT,24);
    

    That should use the pt unit instead of sp. Which might make the text appear the same as inside the WebView. Another thing to consider however, is that WebView has a zoom factor. Even if the fonts are the same size the WebView could be zoomed in/out whereas a default TextView cannot, which would also result in the fonts being different sizes on the screen.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

trying to get same string on tooltip as is in the Text e.g. Text=<%#
I am trying to get the text to scroll at the same speed as
I'm trying to get a button which looks exactly the same whether it is
I'm trying to get it to verify that it has the same item in
I'm trying to get the def wfsc_pod1 and wfsc_ip into the same def. I'm
I am trying to use Twitter Bootstrap for GWT and get the same nice
I'm kinda stuck on something... I'm trying to get #right to be the same
I'm trying to do the same as Get the key corresponding to the minimum
I'm trying to get the custom 404 page we've built to display instead of
I am trying to get a logo to have the same scaling no matter

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.