코드에서 TextView에 스타일 지정하는법
조회수 2078회
코드에서 텍스트뷰에 스타일을 지정하려고 생성자에
TextView myText = new TextView(MyActivity.this, null, R.style.my_style );
이런식으로 해봤는데 스타일이 전혀 적용되지않았어요. 그래서
myText.setTextAppearance(MyActivity.this, R.style.my_style)
이런 방법도 해봤지만 역시 안되네요. 어떻게 해야할까요?
1 답변
-
<?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="This is a template" style="@style/my_style" />
코드상에서 스타일을 지정하는건 잘 모르겠지만 우회하는 방법으로 template 레이아웃을 만들고 위에처럼 정의한후에 텍스트뷰에
TextView myText = (TextView)getLayoutInflater().inflate(R.layout.tvtemplate, null);
이런식으로 정의하는 방법이 있습니다.
댓글 입력