Qualify only part of the text

Write html tag in strings

strings.xml


<string name="hoge"><![CDATA[<font color=#f50057><b>Hoge!</b></font>But<br><font color=#304ffe><b>ふBut!</b></font>It is now possible]]></string>

Creating a Util class

HtmlCompat


public class HtmlCompat {

    @SuppressWarnings("deprecation")
    @SuppressLint("NewApi")
    public static Spanned fromHtml(String source) {
        if (VersionUtil.isNougatOrLater()) {
            return Html.fromHtml(source, Html.FROM_HTML_MODE_LEGACY);
        } else {
            return Html.fromHtml(source);
        }
    }
}

use

activity


text.setText(
        HtmlCompat.fromHtml(activity.getString(R.string.hoge))
);

Like this (including xml settings)

スクリーンショット 2017-07-13 午後3.48.48.png

Recommended Posts

Qualify only part of the text
Replace only part of the URL host with java
Display text on top of the image
part of the syntax of ruby ​​on rails
[Java] The confusing part of String and StringBuilder
The world of clara-rules (2)
Introduction of Docker --Part 1--
[Active Admin] Color the title (panel) part of the form
Judgment of the calendar
study of dbpedia part 25
The world of clara-rules (4)
The world of clara-rules (1)
The world of clara-rules (3)
Until the use of Spring Data and JPA Part 2
[SwiftUI] How to specify the abbreviated position of Text
The world of clara-rules (5)
Until the use of Spring Data and JPA Part 1
The idea of quicksort
I am keenly aware of the convenience of graphql-code-generator, part 2
The idea of jQuery
The story of raising Spring Boot from 1.5 series to 2.1 series part2
I want to expand the clickable part of the link_to method
Get only the ID of the container specified by docker ps
Turn off the format function only in the specified part in Eclipse
About the handling of Null
Docker monitoring-explaining the basics of basics-
Output about the method Part 1
About the description of Docker-compose.yml
Understand the basics of docker
The play of instantiating java.lang.Void
I've only heard of Docker ...
Explanation of the FizzBuzz problem
The basics of Swift's TableView
Form part attributes of form_with
Median of the three values
The illusion of object orientation
Switch the version of bundler
Part 4: Customize the behavior of OAuth 2.0 Login supported by Spring Security 5
I made a gem to post the text of org-mode to qiita
[Java] Appropriate introduction by the people of Tempa Java Part 0 (Code rules)