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

0

I applied a different color to certain words within some TextViews with the% TAG of%.

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

Trying to avoid this, I thought about doing a version of <font color='#2086F3'></font> for newer versions and one for older versions of Android.

It would look something like this:

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>

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

    
asked by anonymous 21.07.2018 / 00:54

1 answer

2

Yes, it is possible.

The strings declared in strings.xml are resources and just like any resource they can have declarations < a href="https://developer.android.com/guide/topics/resources/providing-resources#AlternativeResources"> version alternatives / device features .

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

Inferred APIs will use the strings.xml default, those with equal or higher APIs will use the new strings.xml .

    
22.07.2018 / 11:19