본문 바로가기

HTML

[Android] String 에서 Html Tag만 제거하는 방법 제목 그대로 Html Tag가 포함된 문자열에서 String 값만 빼오는 방법 이다. public String stripHtml(String html) { return Html.fromHtml(html).toString(); }http://stackoverflow.com/a/7389663/3534559 정말 최고의 방법 인듯!!! 참고하세요. 더보기
[Android] TextView에 HTML 코드를 넣을 때 TextView에 HTML 태그를 넣을 수 있습니다. 아래와 같은 태그들을 사용 되는 되요. http://commonsware.com/blog/Android/2010/05/26/html-tags-supported-by-textview.html간편하게 아래 소스 형태로 TextView에 넣으시면 문제 없이 태그가 적용이 되는 것을 확인 할 수 있습니다.SpannableString spanText = new SpannableString(Html.fromHtml(htmlText)); 하지만!!span 태그를 이용하여 Color를 넣고자 할 경우가 있습니다.이럴 경우에는 아래와 같이 font 태그로 replace 시켜 주세요. String htmlText = txt.replace("span style=\"col.. 더보기
[Android] Textview에 link 달기 Textview를 뿌릴 때, bold나 html 링크형태를 동적으로 변경해야할 경우가 있습니다.이럴 경우, TextView에 HTML 형태를 이용하여 변경이 가능 합니다. txt.setText(Html.fromHtml("My Text is going here...." + "Terms and Conditions. ")); txt.setMovementMethod(LinkMovementMethod.getInstance());위 형태와 같이Html 클래스의 fromHtml 함수를 이용하여 html에 태그를 다양하게 이용할 수 있습니다. 참고로 bold 형태만 줄려면, 그냥 strings.xml에 텍스트 형태로 넣어줘도 문제 없이 동작 합니다. Bold no bold 더보기