[Solved] How to increase font size in strings.xml in android

I have string which should look like below

 <string name="text">
    <![CDATA[Text in bigger font size 20.. Text in normal font size 10
        ]]>
    </string>

Any idea or inputs whether this can be achievable? It is preferable if I use CDATA tag, but unfortunately the font tag isn’t working inside the CDATA. The font through the text remains the same even if I set the size..
I will consume this string in a TextView.

Solution #1:

<string name="text">
    <font size="20">Text in bigger font size 20..</font><font size="10"> Text in normal font size 10</font> 
</string>
Respondent: user3747512

Solution #2:

I know this question has been here for so long but seems like there is no proper answer.

In your strings.xml file you put

<string name="text">
<![CDATA[<font size="20">Text in bigger font size 20.. </font><font size="10">Text in normal font size 10</font>]]> </string>

And in your java code file
put this line

textview.setText(Html.fromHtml(getResources.getString(R.string.text)));
Respondent: elin

Solution #3:

Strings are strings and a TextView is a visual tool to display a string.

You should put the text size in the TextView definition in the XML

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="20sp"/>

Or in the code

TextView text = findViewById(R.id.text);
text.setTextSize(20);
Respondent: Jay Ryu

Solution #4:

Use android:textSize in the TextView tag inside your layout file

eg:

 <TextView
    android:layout_marginBottom="100dp"
    android:textStyle="bold"
    android:textSize="50sp"
    android:textColor="#ff1917ff"
    android:layout_gravity="center"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />
Respondent: khumche

Solution #5:

You can use a span to change font size of a portion of text.

See this answer for span code.

In your case you can set size to 10 and span with double the size for the first portion.

Respondent: Vipul Thakur

Solution #6:

Try this inside :-

android:textSize="20sp"
Respondent: Oguz Babaoglu

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Leave a Reply

Your email address will not be published.