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

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

    You can try this: In a fragment :

    @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
    
    View rootView = inflater.inflate(
                    R.layout.shipment_accepted_fragment,
                    container, false);
    
            String email = "(abc@gmail.com)";
    
            TextView shipment_email = (TextView) rootView
                    .findViewById(R.id.textview);
            String text_shipment_email = "Hello"
                    + " " + email
                    + ""
                    + "Bye";
            shipment_email.setText(Html.fromHtml(text_shipment_email),
                    TextView.BufferType.SPANNABLE);
    }
    

提交回复
热议问题