와 특수 문자를 얻을 : 내가하고 싶었던 것을내가 어떻게이 같은 3 문자열이 단어와 클릭 이벤트
"@Username: Deliverd your order",
"YOU got trophy: KING OF COINS",
"There is a package waiting for you to pick up from #surat to #mumbai",
는 클릭 이벤트와 다른 색으로 사용자 이름과 도시 이름을 얻을 수 있습니다.
나는 ":"문자로 나눠서 사용자 이름을 얻을 수 있습니다. 하지만 도시 이름을 얻고 두 이벤트를 모두 알 수는 없습니다.
도시 이름은 도시 이름 색상 만 변경하고 클릭 이벤트는 어떻게 변경합니까?
if (notifications.getTitle().contains(":"))
{
String[] username = notifications.getTitle().split(":");
String uname = getColoredSpanned(username[0] + ":", "#ff7505");
String txt = getColoredSpanned(username[1], "#000000");
holder.txtTitle.append(Html.fromHtml(uname +" " + txt));
holder.txtTitle.setMovementMethod(LinkMovementMethod.getInstance());
}
else if (notifications.getTitle().contains("#"))
{
Matcher matcher =
Pattern.compile("#\\s(\\w+)").matcher(notifications.getTitle());
i=0;
while (matcher.find())
{
place.add(i, matcher.group(1));
i++;
}
String place1 = getColoredSpanned("#" + place.get(0), "#237BCD");
String place2 = getColoredSpanned("#" + place.get(1), "#237BCD");
places1 = notifications.getTitle().replace("#" + place.get(0), place1);
places1 = notifications.getTitle().replace("#" + place.get(1), place2);
holder.txtTitle.setText(Html.fromHtml(places1));
}
else
{
holder.txtTitle.setText(notifications.getTitle());
}
private String getColoredSpanned(String text, String color) {
String input = "<font color=" + color + ">" + text + "</font>";
return input;
}
이 내가 출력으로 무엇을 얻을 :
이
내가 뭘하려을이 정말 기대했던 것입니다 :
https://stackoverflow.com/questions/10696986/how-to-set-the-part-of-the-text-view-is-clickable – vlatkozelka
텍스트에서 데이터를 가져 오는 방법은 포맷을 시도해보십시오. 당신의 문자열을 split(), 아마도 json을 사용하기보다는 구문 분석하기가 더 쉽다. – vlatkozelka
나는 귀하의 링크를 시도했지만 클릭 이벤트를 얻을 수 있지만 색상을 설정할 수 없습니다. –