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

后端 未结 9 1849
暗喜
暗喜 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:50

    Try this..

    TextView update= (TextView) dialog.findViewById(R.id.address);
    String colorText= "Driver is nearby "
                    + ""
                    + "43, KR Rd, Tata Silk Farm, Jayanagar"
                    + ""
                    + " and he is "
                    + ""
                    + "11 km"
                    + ""
                    + " & "
                    + ""
                    + "20 mins"
                    + ""
                    + " away from your current location.";
    
            update.setText(Html.fromHtml(colorText));
    

    and the result will be like this..

    result

提交回复
热议问题