코드에서 TextView에 스타일 지정하는법

조회수 2080회

코드에서 텍스트뷰에 스타일을 지정하려고 생성자에 TextView myText = new TextView(MyActivity.this, null, R.style.my_style ); 이런식으로 해봤는데 스타일이 전혀 적용되지않았어요. 그래서 myText.setTextAppearance(MyActivity.this, R.style.my_style) 이런 방법도 해봤지만 역시 안되네요. 어떻게 해야할까요?

1 답변

  • 좋아요

    0

    싫어요
    채택 취소하기
    <?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); 이런식으로 정의하는 방법이 있습니다.

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)