Is it possible to change the text color in a string to multiple colors in Java?

后端 未结 9 1827
暗喜
暗喜 2020-11-27 04:37

What I mean is, is it possible to change the text \"This text is blue\" to the color blue in a single string? There must be a way...



        
9条回答
  •  一整个雨季
    2020-11-27 04:53

    Html.fromHtml(String) is deprecated in Android N

    To support latest version of Android so something like this

     val colorText = ("Some Normal Text\n" 
                        + " Orange Text "
                        + "More Normal text")
    
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                venueAddressValue.setText(Html.fromHtml(colorText, Html.FROM_HTML_MODE_LEGACY));
            } else {
                venueAddressValue.setText(Html.fromHtml(colorText));
            }
    

提交回复
热议问题