user3224332
user3224332

Reputation: 31

Text size not scaling with system settings font size

I am fixing up an application that someone before me had created and was noticing some strange behavior. Some of the text size, on my main menu particularly, is not changing when I change my font size in my system settings. Here is the code for setting up the text size in my activity. The value in question is landing_text_size

        int height = (int) displayHeight;
    int width = (int) displayWidth;
    textSize = getApplicationContext().getResources().getDimension(
            R.dimen.landing_text_size);
    textViewHeight = (int) ((textSize * 2) + 40);
    // int separatorHeight = (int) getApplicationContext().getResources()
    // .getDimension(R.dimen.landing_grid_margin);
    int space = (int) ((getApplicationContext().getResources()
            .getDimension(R.dimen.landing_grid_view_space)));
    columnWidth = (int) ((height
            - ((int) (getApplicationContext().getResources()
                    .getDimension(R.dimen.landing_header_size)))
            - ((int) (getApplicationContext().getResources()
                    .getDimension(R.dimen.landing_footer_size)))
            - (textViewHeight * numberOfRows) - (space * numberOfRows)) / numberOfRows);

    gridView = (GridView) findViewById(R.id.gridViewLandingPage);
    gridView.setColumnWidth(columnWidth);
    initializeGridView();

    gridView = (GridView) findViewById(R.id.gridViewLandingPage);
    gridView.setColumnWidth(columnWidth);

And later on the code where it sets the text size for the text view.

textView.setTextSize(textSize);

I have been looking into different ways to establish text-size in your xml files and found this question: What is the difference between "px", "dp", "dip" and "sp" on Android?

The obvious idea would be to use sp when declaring my text-size in my dimensions file. The thing is, I am.

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <dimen name="landing_image_size">70dp</dimen>
    <dimen name="landing_header_size">40dp</dimen>
    <dimen name="product_image_size">100dp</dimen>
    <dimen name="stories_image_size">91dp</dimen>
    <dimen name="landing_footer_size">60dp</dimen>
    <dimen name="slide_max_size">140dp</dimen>
    <dimen name="tab_size">100dp</dimen>
    <dimen name="landing_text_size">7sp</dimen>
    <dimen name="landing_grid_view_space">10dp</dimen>

</resources>

When I change my font-size in system settings, the text size does not change in my application. I know I have the right value, because when I change it to say, 10 sp the text gets larger. The project is using api 4.1.2, same as my phone. What could be going wrong? Why isn't the text-size changing?

Upvotes: 0

Views: 964

Answers (1)

Dhara Jogi
Dhara Jogi

Reputation: 66

I dont have enough reputation points so adding as an answer.. The font size in your application wont change as you have specified in your dimens.xml to use that font size.If you will remove the font size from dimens.xml i think the font size will increase when you increase the system font size.

Upvotes: 1

Related Questions