How to convert part of a string to italics?

后端 未结 3 1931
一个人的身影
一个人的身影 2021-01-22 11:44

I want to make animal.getScientificName as Italics(code below). I\'m using a List View and setting the text in the listview. I wan\'t only part of the Text view to

3条回答
  •  南笙
    南笙 (楼主)
    2021-01-22 11:57

    I would recommend using two TextViews, because it is impossible to have two different text-styles in one TextView.

    Just place them both under each other, and assign the correct String value to the TextView.

    tv1.setText(animal.getName().toUpperCase().replaceAll( "_" , " " );
    tv2.setText(animal.getScientificName();
    

    And for example, you can use this layout in your ListView item:

    
    
    
    
        
    
        
    
    
    

提交回复
热议问题