how to make thumbnail image with initials two char from name android?

前端 未结 4 642
粉色の甜心
粉色の甜心 2021-01-06 04:14

I want to thumbnail initials with two word for my image view like \"Peter Parker\" but am able to get only one word \"P\"while running code how can get second word after spa

4条回答
  •  既然无缘
    2021-01-06 04:54

    Hi you can using following way

    String str = "FirstWord SecondWOrd";
            String[] strArray = str.split(" ");
            StringBuilder builder = new StringBuilder();
            if (strArray.length > 0)
                builder.append(strArray[0], 0, 1);
            if (strArray.length > 1)
                builder.append(strArray[1], 0, 1);
            Log.d("New Text" , builder.toString());
    

提交回复
热议问题