TextView에 html코드 넣어 꾸미기.


작업하다가 까먹지 않기 위해...다른 블로그에서 퍼온 자료이다.


//굵은글씨, 진하게

myTextView1 = (TextView)findViewById(R.id.myTextView1);
myTextView1.setText(Html.fromHtml("<b>"+co[0]+"</b>"));


//이탤릭
myTextView2 = (TextView)findViewById(R.id.myTextView2);
myTextView2.setText(Html.fromHtml("<i>"+co[1]+"</i>"));


//밑줄
myTextView3 = (TextView)findViewById(R.id.myTextView3);
myTextView3.setText(Html.fromHtml("<u>"+co[2]+"</u>"));


//글씨 색. 보통은 xml에서 지정
myTextView4 = (TextView)findViewById(R.id.myTextView4);
myTextView4.setText(Html.fromHtml("<font color=\"red\">"+co[3]+"/font>"));


//스타일 중첩. xml파일에서 하지 못하는, 부분적으로 글씨색 바꾸기가 가능하다.
myTextView5 = (TextView)findViewById(R.id.myTextView5);
myTextView5.setText(Html.fromHtml("<b>"+str[0]+"</b> "+

"<font color=\"red\"><i>"+str[1]+" </i></font>"+
"<font color=\"green\"><b><i><u>"+str[2]+"</b></i></u></font>"));


=> 핵심 코드 


Html.fromHtml("<b>"+str[0]+"</b> "+
"<font color=\"red\"><i>"+str[1]+" </i></font>"+

"<font color=\"green\"><b><i><u>"+str[2]+"</b></i></u></font>") 


<출처 : http://devbible.tistory.com/5>

블로그 이미지

미네르바98

안드로이드와 영화 리뷰, 생활정보에 관한 내용을 기재합니다.

,