10

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.

user3747512
  • 203
  • 1
  • 6
  • 15

6 Answers6

23
<string name="text">
    <font size="20">Text in bigger font size 20..</font><font size="10"> Text in normal font size 10</font> 
</string>
elin
  • 538
  • 4
  • 6
4

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)));
Jay Ryu
  • 977
  • 8
  • 7
2

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);
khumche
  • 82
  • 5
1

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" />
Catalina
  • 1,954
  • 1
  • 17
  • 25
Vipul Thakur
  • 54
  • 1
  • 9
1

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.

Community
  • 1
  • 1
Oguz Babaoglu
  • 299
  • 2
  • 7
0

Try this inside :-

android:textSize="20sp"