Set style for TextView programmatically

后端 未结 12 1794
南方客
南方客 2020-11-22 09:47

I\'m trying to use the TextView constructor with style like this:

TextView myText = new TextView(MyActivity.this, null, R.style.my_style);
         


        
12条回答
  •  时光取名叫无心
    2020-11-22 10:24

    You can create a generic style and re-use it on multiple textviews like the one below:

    textView.setTextAppearance(this, R.style.MyTextStyle);
    

    Edit: this refers to Context

提交回复
热议问题