Is it possible to use a specific Strings.xml for the Android version?

Asked

Viewed 26 times

0

I applied a different color to certain words within some Textviews with the TAG <font color='#2086F3'></font>.

I was able to get this result after an Internet search. The problem is that this feature only works for more current versions of Android, in older versions the word is even displayed.

Trying to avoid this, I thought I’d do a version of strings.xml for newer versions and one for older versions of Android.

It would be something like that:

Newer version strings.xml:

<string name="txt_fone">Informe seu <font color='#2086F3'>telefone</font> com DDD</string>
<string name="txt_email">Informe seu <font color='#2086F3'>email</font></string>

Older version strings.xml:

<string name="txt_fone">Informe seu telefone com DDD</string>
<string name="txt_email">Informe seu email</string>

It is possible to load a specific XML for the Android version, or if it exists, some command or conditional TAG that opts for one or another code?

1 answer

2


Yes, it is possible.

The strings declared in xml strings. sane Resources and just like any Resource they may have statements alternatives per version/device characteristics.

Create a new xml strings. for the version (API) from which you want to use <font color='#2086F3'></font>.

Lower API devices will use the xml strings. standard, those with the same or higher API will use the new xml strings..

Browser other questions tagged

You are not signed in. Login or sign up in order to post.