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 6317895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T15:34:59+00:00 2026-05-24T15:34:59+00:00

The official documentation does not seem to answer this, or I can’t figure it

  • 0

The official documentation does not seem to answer this, or I can’t figure it out.

Element (nevermind the AlertDialog, it happens on any TextView as well):

TextView tv = (TextView) dialog.findViewById(android.R.id.message);

Inconsistency. Case A:

tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
// or tv.setTextSize(14); does the same

Case B:

tv.setTextSize(getResources().getDimension(R.dimen.text_size_small));
// TypedValue makes no difference either.

where values/dimens.xml has it:

<dimen name="text_size_small">14sp</dimen>

Result: font size is not the same, and appears much bigger when retrieving from resource. I’m probably missing something, so what’s my mistake, and the most important: why?

— UPDATE TO FIRST ANSWER —

The fixed number was just an example, as nobody would hard code fixed font sizes in code. So let me rephrase the question:

Why if I get the resource from code, the text size is bigger than when I get the resource from a XML layout? Besides, the question is still the same: how do I retrieve a 14sp unit in code and keep it consistent with the 14sp unit that is set in the layout XML? I did not accept the answer because it does not tell me how to use sp units from resource in code for text size.

On this layout, the font size is different, even if the dimension is the same:

<TextView
            android:id="@+id/my_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            style="@style/TextBody" />

styles.xml:

<style name="TextBody">
    <item name="android:textSize">@dimen/text_size_small</item>
    <item name="android:lineSpacingMultiplier">1.1</item>
    <item name="android:textColor">@color/body_text_1</item>
    <item name="android:textIsSelectable">true</item>
    <item name="android:linksClickable">true</item>
</style>

See text_size_small there? Why in this case the font size is smaller than in the code, using the same dimen resource?

  • 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-05-24T15:35:00+00:00Added an answer on May 24, 2026 at 3:35 pm

    You should use setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); because the documentation of the getDimension method states that it returns a Resource dimension value multiplied by the appropriate metric. which I understand to be the precalculated absolute px value.

    That is, use:

    tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.text_size_small));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The official Web Agents user documentation does not state what version of SAML is
Does anyone have examples/tutorials of exception handling in R? The official documentation is very
The official oauth guide makes this recommendation: It is important not to try and
Can someone confirm that Python 2.6 ftplib does NOT support Unicode file names? Or
From the official documentation I can't understand what is default parameter. obj, created =
Beyond the official documentation, are there any recommended resources for learning to build jQuery
Is there official documentation on the Python website somewhere, on how to install and
Here's the information according to the official documentation : There are four different pairs
I've looked on Wikipedia, googled it, and read the official documentation, but I still
Here is a snippet of the official Apple Documentation of AudioBufferList (Core Audio Data

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.